43

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.

Is there any way to remove this?

TylerH
  • 20,799
  • 66
  • 75
  • 101
OVERTONE
  • 11,797
  • 20
  • 71
  • 87

7 Answers7

89

<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.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • 1
    I'm only using P so i can give it an id. What would you recommend. I avoiding using divs as I already have too many. – OVERTONE Jul 29 '11 at 14:41
  • 1
    Li and Ul seem to have default margins and padding too. Thank you so much. This saved me a world of trouble! – OVERTONE Jul 29 '11 at 14:41
  • It depends why you want to give it an id. You could give the `
  • ` an id.
  • – Quentin Jul 29 '11 at 14:44
  • 2
    Or you could use a `` instead of a `

    ` to add that Id :)

    – Erenor Paz Feb 02 '15 at 16:16
  • That didn't work for me. I needed to add `display` property with `inline` value: `display: inline ;` to the CSS (without `margin: 0` and `padding: 0`) to get it working. – 15 Volts Nov 04 '19 at 12:31
  • 1
    @S.Goswami — Then something else was interfering. All else being equal, this will work. – Quentin Nov 04 '19 at 17:02