inline-block list items mess up when one is empty

后端 未结 4 972
萌比男神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:00
    ul li {display:block; float:left;} 
    

    works for me.

    JSFiddle

    0 讨论(0)
  • 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;
    }
    <ul>
      <li>
    
        <!--no content list item, why it mess up align to top others-->
      </li>
      <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
    </ul>

    0 讨论(0)
  • 2021-01-28 06:20

    overflow: hidden; is missing into "ul li { }"

    Use this:

    ul li {
      font-size: 14px;
      display: inline-block;
      width: 50px;
      background-color: red;
      border: solid black 1px;
      height: 38px;
      margin: 0px;
      padding: 0px;
      text-align: center;
      overflow: hidden;
    }
    
    0 讨论(0)
  • 2021-01-28 06:25

    Add vertical-align: top; to your li elements.

    0 讨论(0)
提交回复
热议问题