Home  >  Q&A  >  body text

How can a UL item stay within its containing DIV?

<p>I have a very simple setup: </p> <pre class="brush:php;toolbar:false;"><div class="container"> <ul> <li>Project 1</li> <li>Project 2</li> </ul> </div></pre> <p>I would have thought that all the content and the UL's bullet points would be inside the div, but that's not currently the case. </p> <p>UL's bullets appear outside the div, and when the overflow is hidden, they actually disappear. </p> <p>To me this is problematic in some way, and this problem exists in various browsers, I've looked up the HTML specification but can't find anything about how this should happen illustrate. </p> <p>Is there a CSS fix or other layout fix? </p>
P粉714780768P粉714780768424 days ago527

reply all(2)I'll reply

  • P粉020085599

    P粉0200855992023-08-23 21:12:32

    list-style-position: inside Works fine in most cases, unless you need multi-line bullets on small screens, as this will cause the text to align with the bullets instead of Aligned to the starting position of the text.

    Keeping the default text-align: outside, which allows a small margin and left-aligns the text to cover any centered containers, can solve bullet alignment problems.

    ul, ol {
      margin-left: 0.75em;
      text-align: left;
    }

    reply
    0
  • P粉085689707

    P粉0856897072023-08-23 00:14:09

    You will need to use list-style-position:

    ul {
       list-style-position: inside;
    }

    reply
    0
  • Cancelreply