I want my headers (h1 through h6) to have a background colour (different to that of the page background), I also want the width of this background to be the same as the width of the text in the header, plus padding (Not the width of the container that the header is in, which is what is happening now).
There isn't much point in me showing you any code as this is fairly simple (or it should be anyway!). The container is a fixed width. Right now I have just some margins, padding, background colour and font styling set for the h1, h2, h3 etc tags.
EDIT: I guess code would help! https://web.archive.org/web/20090724165158/http://adriantrimble.com/headers (this has Gerald's solution applied, although obviously this would still not work in IE6/7 and still has problems in newer browsers). Using display:inline causes more problems than it solves, using float: left and clear: left as mentioned has problems because of the 2 column layout. Thanks for everyones help so far.
Hummer H1 Length, Width, Height & Wheelbase Overview The Hummer H1 is 15.4 feet (4.69 meters) long. The Hummer H1 is 7.2 feet (2.2 meters) wide. The Hummer H1 has a height ranging from 6.2 feet (1.91 meters) to 6.6 feet (2.01 meters), depending on the trim and model year.
H2 heading tag Like an H1 tag, an H2 tag also appears larger than the rest of your main body text. However, H2 tags are always slightly smaller than your H1 tag, so that it does not compete with your main heading.
The structure of H1, H2, H3 tags For an article or webpage, remember that the H1 title is the most important section. H2 and H3 are used to organize sub-sections, while H4, H5 and H6 are intended to provide additional information, with more details.
The H1 heading should be the largest heading on the page. The H2 heading is a little smaller than the H1 , and in turn the H3 heading is smaller than then H2 heading and so on.
h1-h6 are block level elements and even if they are not in a container (or just body) they'll stretch over the width of the window. One solution is to change their display to be inline-block instead:
<h1 style="background-color:pink; display:inline-block; padding:1em;">Testheader</h1>
Note that you'd have to make a manual break after the header if the next element isn't a block-level element like p.
I would use
#rightcol h1, #rightcol h2, #rightcol h3, #rightcol h4, #rightcol h6, #rightcol h6 {
float:left;
clear:left;
}
#rightcol p {clear:left;}
edit after comment
If the containing div is floated, the clear won't clear the left col. So float rightcol left and remove the margin
#rightcol {
float:left;
padding:70px 20px 20px 0px;
width:585px;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With