How do I center list items inside a UL element?

后端 未结 12 2529
旧时难觅i
旧时难觅i 2020-11-29 23:12

How do I center list items inside a ul without using extra divs or elements. I have the following. I thought text-align:center would do the trick. I can\'t seem

12条回答
  •  猫巷女王i
    2020-11-29 23:18

    A more modern way is to use flexbox:

    ul{
      list-style-type:none;
      display:flex;
      justify-content: center;
    
    }
    ul li{
      display: list-item;
      background: black;
      padding: 5px 10px;
      color:white;
      margin: 0 3px;
    }
    div{
      background: wheat;
    }
    • One
    • Two
    • Three

提交回复
热议问题