How do I set vertical space between list items?

后端 未结 9 1129
暖寄归人
暖寄归人 2020-12-24 04:11

Within a

    element, clearly the vertical spacing between lines can be formatted with the line-height attribute.

    My question is, within a

相关标签:
9条回答
  • 2020-12-24 04:36

    HTML

    <ul>
       <li>A</li>
       <li>B</li>
       <li>C</li>
       <li>D</li>
       <li>E</li>
    </ul>
    

    CSS

    li:not(:last-child) {
        margin-bottom: 5px;
    }
    

    EDIT: If you don't use the special case for the last li element your list will have a small spacing afterwards which you can see here: http://jsfiddle.net/wQYw7/

    Now compare that with my solution: http://jsfiddle.net/wQYw7/1/

    Sure this doesn't work in older browsers but you can easily use js extensions which will enable this for older browsers.

    0 讨论(0)
  • 2020-12-24 04:41

    Many times when producing HTML email blasts you cannot use style sheets or style /style blocks. All CSS needs to be inline. In the case where you want to adjust the spacing between the bullets I use li style="margin-bottom:8px;" in each bullet item. Customize the pixels value to your liking.

    0 讨论(0)
  • 2020-12-24 04:43

    Add a margin to your li tags. That will create space between the li and you can use line-height to set the spacing to the text within the li tags.

    0 讨论(0)
  • 2020-12-24 04:49

    setting padding-bottom for each list using pseudo class is a viable method. Also line height can be used. Remember that font properties such as font-family, Font-weight, etc. plays a role for uneven heights.

    0 讨论(0)
  • 2020-12-24 04:51

    Old question but I think it lacked an answer. I would use an adjacent siblings selector. This way we only write "one" line of CSS and take into consideration the space at the end or beginning, which most of the answers lacks.

    li + li {
      margin-top: 10px;
    }
    
    0 讨论(0)
  • 2020-12-24 04:51

    <br>between <li></li> line entries seems to work perfectly well in all web browsers that I've tried, but it fails to pass the on-line W3C CSS3 checker. It gives me precisely the line spacing I am after. As far as I am concerned, since it undoubtedly works, I am persisting in using it, whatever W3C says, until someone can come up with a good legal alternative.

    0 讨论(0)
提交回复
热议问题