Can inline elements contain block elements?

前端 未结 7 1706
春和景丽
春和景丽 2021-01-20 16:16

Can an inline element contain a block element for instance: can a list have a paragraph?

7条回答
  •  没有蜡笔的小新
    2021-01-20 16:28

    Leaving aside the fact that LI and P are both block level ...

    It's never valid to do so, but in behavioural terms, sometimes you can nest a block level element inside a inline level one, but it depends on the browser parser.

    For example, in FireFox 3.x, with this markup

    
    
       foo
       
    bar
    baz

    will display foo, bar, and baz all in italics.

    But this markup, replacing the inline element with inline element (which also has italics as its default rendering)

    
    
       foo
       
    bar
    baz

    will only display foo in italics.

    JSFiddle for this

    Other browsers do not behave the same. Which is one reason why you should stick to using valid markup.

提交回复
热议问题