Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove space between paragraph and unordered list

Tags:

html

css

<p>Text</p> <ul>   <li>One</li> </ul>  <p>Text 2</p> 

How do i remove the vertical space between paragraph and the list.

To be more specific - how do I reduce the bottom margin/padding of the p tag ONLY when followed by an unordered list. All the answers I see here remove the space after all p tags - that's not what was asked.

like image 411
user544079 Avatar asked Oct 13 '11 19:10

user544079


People also ask

How do I remove spaces in UL?

The padding-left:0 is used to remove indentation (space) from left. The list-style: none property is used to remove list-style property from the list of items.


2 Answers

One way is using the immediate selector and negative margin. This rule will select a list right after a paragraph, so it's just setting a negative margin-top.

p + ul {      margin-top: -XX; } 
like image 25
polypiel Avatar answered Oct 07 '22 16:10

polypiel


You can use CSS selectors in a way similar to the following:

p + ul {     margin-top: -10px; } 

This could be helpful because p + ul means select any <ul> element after a <p> element.

You'll have to adapt this to how much padding or margin you have on your <p> tags generally.

Original answer to original question:

p, ul {     padding: 0;     margin: 0; } 

That will take any EXTRA white space away.

p, ul {     display: inline; } 

That will make all the elements inline instead of blocks. (So, for instance, the <p> won't cause a line break before and after it.)

like image 69
Joe Hansen Avatar answered Oct 07 '22 18:10

Joe Hansen