I have a weird problem with paragraph margins collapsing when i insert a list. Say I have the following code:
<p>
text
<ul>
<li>list</li>
</ul>
more text
</p>
Paragraphs and ul’s both have 20px bottom margins in this code (css styled). However in the above example, the margin under “more text” disappears. To get it back, I have to enclose “more text” in its own p tags, like this:
<p>
text
<ul>
<li></li>
</ul>
</p>
<p>
more text
</p>
Thanks, I will do that from now on. But is the behavior I described normal for a situation like that (list inside paragraph)? I am not used to my margins just evaporating into thin air!
That is completely invalid markup! A p element cannot contain a ul.
Since the </p> end-tag is optional in HTML, the paragraph will be closed before the list starts. Then you’ll get a superfluous </p> after the list and some dangling text.