W3C home > Mailing lists > Public > www-style@w3.org > December 2000

Re: width of content+padding versus border+margin

From: Matthew Brealey <webmaster@richinstyle.com>
Date: 15 Dec 2000 18:02:48 -0000
Message-ID: <20001215180248.27317.qmail@phoenix.futurequest.net>
To: www-style@w3.org
--- Steve Clark <buster@netscape.com> wrote: 
> > I'm trying to create H2 output such that the content appears with a
> > background colour that occupies an area only moderately larger than the
> content itself. 
> by default, block level elements expand to the width of their parents.  
> 
> I'd guess in your case the parent has no specified width, so it's the 
> width of the browser window.  Inline frames, on the other hand, are 
> sized based on their content.
> 
> You could set an explicit width on the H2.  Or if you want the H2 to be 
> springy, but want the background color to map to the text, you should 
> probably do something  like this:
> 
> <style>
>   span {
>     display:inline;
>      background: #066; padding: 3pt;
>   }
> </style>
> 
> <H2><span>content</span><H2>

That won't work. Only the text is coloured of inline text - not its padding. 

> > (PS: I get the desired content/background effect by declaring the H2 to be
> > "inline" instead of "block", but I want a block-mode heading.)

If you write well-formed XHTML, this won't be a problem

<p>
paragraph
</p>
<h2>
Heading
</h2>
<p>
Paragraph
</p>

There the fact that the elements around it will be block, means that it
won't be noticeable that the h2 is inline.

-- Random (non-anti-Microsoft) fortune
I'm gliding over a NUCLEAR WASTE DUMP near ATLANTA, Georgia!!
Received on Friday, 15 December 2000 13:02:27 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:54:06 GMT