List items with same height

后端 未结 8 1232
谎友^
谎友^ 2020-12-18 23:36

I have created a fiddle: http://jsfiddle.net/pQZ8f/

I want to have both the list items to be of same height without setting height manually. I want it to auto grow.

相关标签:
8条回答
  • 2020-12-19 00:31

    You can use: display: inline-table on your LI elements

    li {
        width:100px;
        background: red;
        display: inline-table
    }
    

    here is JSFiddle

    0 讨论(0)
  • 2020-12-19 00:39

    It depends on why you want them the same height: what overall effect are you trying to achieve?

    One option: If you're simply trying to match a background or something, you can put the background on the <ul> instead of the <li>'s and the <ul> will expand automatically to whatever the max height is of its child elements.

    Further, if you're trying to make them the same height so you can align the bottom of the text, you can combine display: inline-block instead of float, and horizontal-align: bottom;. The result in this Fiddle gets you something that at least looks like the <li>'s are the same height, but won't work for borders.

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