Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove space above and below <p> tag HTML

Tags:

html

css

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?

like image 317
OVERTONE Avatar asked Jul 29 '11 14:07

OVERTONE


People also ask

How do I get rid of extra space in P tag?

Setting padding to 0px of the parent paragraph tag will remove the space between parent and child paragraphs if one is inside of another. For Example: P{

How can I eliminate the extra space after a tag in HTML?

Approach 1: We can remove space between any two tags by simply using margin-bottom property. The margin-bottom property sets the bottom margin of an element. We will assign a negative value to the margin-bottom of a particular tag to eliminate the extra space between the tags as shown.

How do I remove the space between two sections in HTML?

How do I reduce the gap between two sections in HTML? Using inline styling, you can identify the paragraphs you wish to remove space from and write in the following: style=”padding: 0px; margin: 0px;”If you want to center all paragraphs, add it to your CSS in the style tag: <style>


2 Answers

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

like image 56
Quentin Avatar answered Oct 20 '22 10:10

Quentin


Look here: http://www.w3schools.com/tags/tag_p.asp

The p element automatically creates some space before and after itself. The space is automatically applied by the browser, or you can specify it in a style sheet.

you could remove the extra space by using css

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

or use the element <span> which has no default margins and is an inline element.

like image 13
Sarah West Avatar answered Oct 20 '22 09:10

Sarah West