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

Re: width of content+padding versus border+margin

From: Steve Clark <buster@netscape.com>
Date: Fri, 15 Dec 2000 09:09:09 -0800
Message-ID: <3A3A5035.5000408@netscape.com>
To: Roger Watt <rwwatt@ist.uwaterloo.ca>
CC: www-style@w3.org
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>

Roger Watt 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. So I started with
> 
>    H2 { background: #066; padding: 3pt; }
> 
> With both NN6 and IE5, what results is a background that extends across
> the full width of the browser's window. So I wondered if perhaps I could
> influence the left/content/right equality
> 
>      width = margin+border+padding + content + padding+border+margin 
> 
> by trying
> 
>    H2 { background: #066; padding: 3pt !important; }
> 
> but that didn't do the trick either.
> 
> Is there something that my repeated readings of the spec have failed to
> detect, or is there simply no way to do this?
> 
> (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.)
> 
Received on Friday, 15 December 2000 12:04:38 GMT

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