How to center an unordered list?

后端 未结 5 836
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 04:43

I need to center an unordered list of unknown width, while still keeping the list-items left aligned.

Achieve the same result as this:

HTML<

5条回答
  •  长情又很酷
    2020-11-27 05:26

    From your post, I understand that you cannot set the width to your li.

    How about this?

    ul {
      border:2px solid red;
      display:inline-block;
    }
    
    li {
      display:inline;
      padding:0 30%; /* try adjusting the side % to give a feel of center aligned.*/
    }
    • Hello
    • Hezkdhkfskdhfkllo
    • Hello

    Here's a demo. http://codepen.io/anon/pen/HhBwx

提交回复
热议问题