idlackage
idlackage

Reputation: 2863

Negating the css property of one class with another

I have this:

<div class="style1 neg">
    <input type="submit" value="blah" />
</div>

And the css:

.style1 {
    float: left;
    margin-top: 25px;
}
.style1 .neg {
    margin-top: 0;
}

I'm trying to negate margin-top, but when I inspect the element in the browser, the 'neg' style seems to be ignored completely. How would I do this properly?

Upvotes: 5

Views: 1891

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191729

The space, , is the descendant selector. .style1 .neg selects a .neg that is a descendant of .style. You want to use .style1.neg

Documentation: http://www.w3.org/TR/css3-selectors/#class-html

In action: http://jsfiddle.net/dH7JJ/

Upvotes: 15

Related Questions