SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    eez
    Posts
    331
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is it OK to mix inline and block elements?

    Hi!

    Is it OK to mix inline and block elements?

    For example:


    <imp ... />

    <p> .... </p>


    Thanks

  2. #2
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,484
    Mentioned
    182 Post(s)
    Tagged
    6 Thread(s)
    What do you mean by mix and what exactly is an imp tag - I've never seen one of those

    inline elements can only contain other inline elements.

    e.g.

    <span><span>nested text</span></span>

    P tags (paragraphs) and heading tags are special block level elements and can contain only inline elements.

    <p><span>text</span></p>

    Elements such as divs are block level and contain other divs and inline elements and anything else I haven't mentioned.

    Perhaps you should read Tommy's article on it.

    http://www.autisticcuckoo.net/archiv...ck-vs-inline-1

    Hope that helps

  3. #3
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://annevankesteren.nl/2005/05/content-models

    In HTML4 it is allowed. The HTML4 spec doesn't discuss this, and the DTD allows some elements to contain both block and inline elements at the same time. However, it seems that in HTML5 (which is still a draft) those elements can only contain either block-level elements or inline level content.
    Simon Pieters

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It depends on the containing element and on the DOCTYPE.

    With a Strict DOCTYPE, the BODY element can only contain block-level elements. In other words, you cannot have this:
    HTML Code:
    <body>
      <img src="x.png" alt="X"> <!--invalid-->
      <p>...</p>
    </body>
    It's allowed with a Transitional DOCTYPE, though, which should be an indication that it's a practice that is frowned upon.

    Some element types, like DIV and LI, allow both inline and block-level children. However, I'm not sure it makes sense, semantically, to mix.
    Birnam wood is come to Dunsinane


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •