Why do my list item bullets overlap floating elements

前端 未结 23 1221
半阙折子戏
半阙折子戏 2020-11-28 18:00

I have an (XHTML Strict) page where I float an image alongside regular paragraphs of text. All goes well, except when a list is used instead of paragraphs. The bullets of th

23条回答
  •  旧巷少年郎
    2020-11-28 18:34

    Adding an improvement to Glen E. Ivey's solution:

    ul {
        list-style: outside disc;
        margin-left: 1em;
    }
    ul li {
        position: relative;
        left: 1em;
        padding-right: 1em;    
    }​
    

    http://jsfiddle.net/mblase75/TJELt/

    I prefer this technique, since it works when the list needs to flow around the floating image, while the overflow: hidden technique will not. However, it's also necessary to add padding-right: 1em to the li to keep them from overflowing their container.

提交回复
热议问题