inline-block list items mess up when one is empty

后端 未结 4 1042
萌比男神i
萌比男神i 2021-01-28 05:22

I wanted to put some image in first list item but it seems to mess up when it\'s no content. i tried various methods in jsfiddle (various options of display and position) but no

4条回答
  •  遇见更好的自我
    2021-01-28 06:20

    you need to reset vertical-align propertie to vertical-align:top; (defaut is baseline and depends on content wich sets the line-height)

    https://www.w3.org/TR/CSS2/visudet.html#propdef-vertical-align

    examples to play with

    ul {
      font-size: 0px;
      display: inline-block;
      height: 40px;
      width: 100%;
      background-color: black;
    }
    ul li {
      font-size: 14px;
      display: inline-block;
      vertical-align:top;
      width: 50px;
      background-color: red;
      border: solid black 1px;
      height: 38px;
      margin: 0px;
      padding: 0px;
      text-align: center;
    }
    div {
      heght: 1.5em;
      margin: 0px;
      padding: 0px;
    }
    • 1
    • 2
    • 3
    • 4

提交回复
热议问题