remove space between paragraph and unordered list

前端 未结 8 2147
情歌与酒
情歌与酒 2021-01-01 10:17

Text

  • One

Text 2

How do i remove the vertical space between par

相关标签:
8条回答
  • 2021-01-01 10:42
    p, ul{
         padding:0; 
         margin:0;
    }
    

    If that's not what your looking for you'll have to be more specific

    0 讨论(0)
  • 2021-01-01 10:46

    Every browser has some default styles that apply to a number of HTML elements, likes p and ul. The space you mention is likely created because of the default margin and padding of your browser. You can reset these though:

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

    You could also reset all default margins and paddings:

    * { margin: 0; padding: 0; }
    

    I suggest you take a look at normalize.css: http://necolas.github.com/normalize.css/

    0 讨论(0)
  • 2021-01-01 10:48

    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;
    }
    
    0 讨论(0)
  • 2021-01-01 10:50

    This simple way worked fine for me:

    <ul style="margin-top:-30px;">
    
    0 讨论(0)
  • 2021-01-01 10:58

    You can (A) change the markup to not use paragraphs

    <span>Text</span>
    <br>
    <ul>
      <li>One</li>
    </ul>
    <span>Text 2</span>
    

    Or (B) change the css

    p{margin:0px;}
    

    Demos here: http://jsfiddle.net/ZnpVu/1

    0 讨论(0)
  • 2021-01-01 11:00

    I ended up using a definition list with an unordered list inside it. It solves the issue of the unwanted space above the list without needing to change every paragraph tag.

    <dl><dt>Text</dt>
    <dd><ul><li>First item</li>
    <li>Second item</li></ul></dd></dl>
    
    0 讨论(0)
提交回复
热议问题