Forum Moderators: not2easy
[webmasterworld.com...]
Would the same work for positioning? This works to slide the content down the right amount:
<div class="spacer_1">
<div class="spacer_2">
<div class="header_1">content</div>
</div>
</div>
But this doesn't:
<div class="spacer_1 spacer_2">
<div class="header_1">content</div>
</div>
Here's the CSS:
div.spacer_1 {font-family:verdana; font-size:small; top:1em; position:relative}
div.spacer_2 {font-family:verdana; font-size:x-small; top:1em; position:relative}
...while in the 2nd you are simply setting the value for 'top' of the outside div to '1em', twice, so to speak. In effect saying "set the top 1em down - set the top 1em down", not "set top 1em down and another 1ems down.."
Did that make sense? In the first you are piling two spaces in top of each other, while in the second you are (twice) setting a space of 1em on the div.
There has to be a better way to explain this!
>>better way = not sure
but it's the cascade at work
<div class="spacer_1 spacer_2">
spacer_2's properties are overruling spacer_1's because spacer_2 classname is the same specificity but is listed later, and so it "wins" by order of the cascade. Multiple classes don't accumulate the same properties, the later one simply overwites the earlier ones..
The only thing according to your CSS that specifying the double class is doing for the div in this case is changing it's font-size
If you want to use mutiple classes for this you could do it like this:
<div class="spacer_1 top_2">
<div class="header_1">content</div>
</div>
div.spacer_1 {font-family:verdana; font-size:small; top:1em; position:relative}
div.top_2 {top:2em;}
so spacer_1 is providing the standard details, but top_2 is being used to override only one property the rest will remain as per spacer_1's rules.
Suzy
.header_1 {
padding: 2em 0 0 0; /* top only set but could apply to bottom too */
margin: 10px 0 0 0; /* top only set but could apply to bottom too */
background: #fcf;
}
<div class="header_1"><h3>content</h3></div>
<div class="header_1">content</div>
<div class="header_1">content</div>
You'll see the "padding" on the first div is more than expected that's due to the default margin on the h3 not collapsing.. but you can control/zero the default margins as required.
Suzy
.header_1 {
padding: 2em 0 0 0; /* top only this could now be either padding or margin */
background: #fcf;
position: absolute;
top: 50px; /* the pixel "spacer" */
}
Suzy