6

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

Frederic Klein
  • 2,816
  • 3
  • 24
  • 37
Manish Basdeo
  • 5,957
  • 21
  • 67
  • 100
  • possible duplicate of [Block Level Elements inside Inline elements](http://stackoverflow.com/questions/1714121/block-level-elements-inside-inline-elements) – JohnP Jun 22 '11 at 12:19
  • 2
    Nope. To answer your second question, a list is not an inline element. A list can contain P or DIV tags or whatever. – JohnP Jun 22 '11 at 12:22

7 Answers7

7

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

<!DOCTYPE html>
<i>
   foo
   <div>bar</div>
   baz
</i>

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

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

<!DOCTYPE html>
<var>
   foo
   <div>bar</div>
   baz
</var>

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.

Alohci
  • 73,780
  • 12
  • 107
  • 149
2

It can, but it won't pass validation. There are ways round it that have been thoroughly discussed here: Is it wrong to change a block element to inline with CSS if it contains another block element?

Community
  • 1
  • 1
David Amey
  • 1,392
  • 1
  • 12
  • 11
0

Inline element can't contain block element and block element can contain all kind of. <li> , that you've mentioned, is not an inline element it's a block element as <p> , so both can contain each others

Haykui
  • 1
0

block-level elements cannot descend from inline-level elements

Eric Meyer book "CSS The dfinitive Guid" page 9

Ayman Morsy
  • 992
  • 6
  • 21
0

It's incorrect markup to use a block element within an inline one. It may still render if the browser and Doctype are lenient, but it's not valid.

You can usee CSS, however, as discussed here.

Community
  • 1
  • 1
Widor
  • 12,605
  • 6
  • 38
  • 62
0

If you want block elements to behave like inline elements, set the display property to inline-block. If you need to support IE 7 or 6, for the same elements in your IE stylesheet, add these two rules: zoom:1; display:inline.

timw4mail
  • 1,626
  • 2
  • 12
  • 16
-5
<li> & <p> both are inline elements. so you can use <p> inside <li>
Ahsan Rathod
  • 5,397
  • 2
  • 19
  • 25