Reputation: 4302
Let's say I have a block element, such as an h2:
<h2>Title</h2>
And I give it a background color. The background will span the entire width of the wrapper (as it should).
If I float it, or position: absolute
, it will 'shrink wrap' the words. However, both of these methods take the element out of the 'flow' and prevent it from pushing the rest of the content down the page.
I'd like to avoid having to add a clear underneath the title every time. Is there a better solution? I thought the overflow
property could do it, but I'm not figuring it out.
fiddle:
Upvotes: 0
Views: 85
Reputation: 213
Wrap the header text in a <span>
and apply the background color to that span.
HTML:
<h2><span class="blue">Title</span></h2>
CSS:
.blue{
background-color:blue;
}
Upvotes: 0