Text indentation in unordered lists with CSS

15,069

Solution 1

You want to use list-style-position:outside on your <ul>

JsFiddle

Solution 2

Please try and use this property

li {
    list-style-position:outside;
} 

or inside one or the other. This should fix the problem.

Share:
15,069
Frank Vilea
Author by

Frank Vilea

Updated on June 11, 2022

Comments

  • Frank Vilea
    Frank Vilea almost 2 years

    I have an unordered HTML list and am using CSS to style everything. When the text has multiple lines, it starts before the bullet point. Is there a way to make it start after the bullet point position?

    enter image description here

  • Anton
    Anton about 13 years
    in your example if i delete list-style-position:outside , then there is no effect on structure.
  • Frank Vilea
    Frank Vilea about 13 years
    Many thanks, I was actually using list-style-position: inside; because I wanted to indent all the bullet points. When I use the outside value I can't seem to apply margin-left/padding-left to the ul/li anymore.
  • Wesley Murch
    Wesley Murch about 13 years
    Yes, it is usually the default. inside will do what appears in OP's example.
  • Frank Vilea
    Frank Vilea about 13 years
    Thanks Kon. I tried it but it seems to cause problems with Firefox.
  • Kon
    Kon about 13 years
    Well, you'll have to make some styling adjustments probably (e.g. margin, padding, display inline?)
  • Wesley Murch
    Wesley Murch about 13 years
    @Frank Vilea: Must be something else in your css, it's working fine here. Mess around with the fiddle if you need to see how float, display properties, etc. affect it. I can't really say what the issue is without seeing code.
  • Frank Vilea
    Frank Vilea about 13 years
    Firefox would start the text on a new line for some strange reason. It used to be pure text so I forgot to apply float: left; to the new bullet point list which was the reason why all these values would not work.
  • Frank Vilea
    Frank Vilea about 13 years
    Thanks, I simply had to apply float: left; which is what I forgot and why it did not work previously.
  • Wesley Murch
    Wesley Murch about 13 years
    Adding divs is more of a last resort when css solutions are available.
  • Kon
    Kon about 13 years
    @Madmartigan, I'd say that's argumentative. Depends on context of the problem.
  • Wesley Murch
    Wesley Murch about 13 years
    @Kon: CSS is for styling documents. HTML is for describing what they contain. Adding a meaningless div into a list item to achieve a visual effect that is easily possible with CSS to me has no advantage or purpose, but I'd be willing to listen to opposition.
  • Kon
    Kon about 13 years
    No, you're right for the most part. I just wouldn't blindly apply CSS to everything without first considering if that's the appropriate solution for the problem at hand.