Re: width of content+padding versus border+margin

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 UTC