Re: width of content+padding versus border+margin

--- 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 UTC