Re: May elements with display:inline contain children with display:block?

Steven Pemberton writes:
> 
> I read and reread the relevant parts of
> http://www.w3.org/TR/REC-CSS2/visuren.html to try and answer this question,
> and couldn't find from the text any reason why not. May elements with
> display:inline contain children with display:block?

Yes, absolutely. I do this occasionally to get a displayed, centered
image:

    img {display: block; margin: auto}

    <p>Some text <img...> more text

There are implicit anonymous blocks before and after the real block,
around any inline elements that are siblings of the block. (It doesn't
matter whether that anonymous block actually exists, in the DOM or
elsewhere, since CSS doesn't allow you to set any properties on it
anyway.)

In HTML it is rare to have blocks inside inlines, but CSS was designed
to allow paragraphs interrupted by displayed material, such as quotes.
It would probably be a good idea to support that in XHTML:

    <p>Some text before the quotation
      <blockquote>"A famous quote"</blockquote>
      and the text continues.</p>

Or mathematical formulas:

    <p>Some text leading to a grand formula,
     <math display=block>...</math>
     after which the text continues.

> 
> Or to put it another way, if in HTML <html> and <body> were display:inline,
> what would break?

Nothing would break, but some properties on html or body (such as
padding, border, line-height) would obviously have different effects.



Bert
-- 
  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/people/bos/                              W3C/INRIA
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 (0)4 92 38 76 92            06902 Sophia Antipolis Cedex, France

Received on Friday, 31 May 2002 09:36:27 UTC