OVERTONE OVERTONE - 3 months ago 6
CSS Question

remove space above and below <p> tag HTML

So simple enough.

Take this ul for example.

<ul>
<li>HI THERE</li>
<br>
<li>
<p >ME </p>
</li>
</ul>


When the innerHtml of an Li tag is blank, the Li wraps itself right up to the text.

It doesn't happen for the P tag. I'm assuming this is because p is for paragraphs which usually have white space breaks before and after.

My question:

Is there any way to remove this?

Answer

<p> elements generally have margins and / or padding. You can set those to zero in a stylesheet.

li p {
    margin: 0;
    padding: 0;
}

Semantically speaking, however, it is fairly unusual to have a list of paragraphs.

Comments