Why do my list item bullets overlap floating elements

前端 未结 23 1117
半阙折子戏
半阙折子戏 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:22

    Try the following on your UL tag. This should take care of the bullets overlaying your image and you don't have to mess up your left allignment caused by list-position: inside.

    overflow: hidden; 
    padding-left: 2em; 
    
    0 讨论(0)
  • 2020-11-28 18:25

    I fixed it with

    div.class-name ul {
      clear: both;
    }
    
    0 讨论(0)
  • 2020-11-28 18:27

    Struggled with this myself. Best I've managed is the following:

    ul {
        list-style-position: inside;
        padding-left: 1em;
        text-indent: -1em;
    }
    

    The text is not actually indented but the bullet shows.

    0 讨论(0)
  • 2020-11-28 18:28

    You could assign position: relative; left: 10px; to the li. (You may additionally want to give it a margin-right: 10px;, otherwise it might become too wide on the right side.)

    Or, if you want to use float for the ul -- as suggested by others -- you can probably stop the rest from floating right of the ul by using clear: left on the element that follows the ul.

    0 讨论(0)
  • 2020-11-28 18:28

    or you could do this:

     #content ul {
            background:none repeat scroll 0 0 #AACCDD;
            float:left;
            margin-right:10px;
            padding:10px;
    

    and then remove all the styling from the li

    0 讨论(0)
  • 2020-11-28 18:29

    By adding overflow: auto; to your ul works for me at least.

    Update

    I've updated my jsfiddle to visualize what's going on. When having the ul beside the floating img, the content of the ul will be pushed by the float, but not the actual container. By adding overflow: auto the whole ul-box will be pushed by the float instead of only the content.

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