Equal sized table cells to fill the entire width of the containing table

后端 未结 3 977
孤城傲影
孤城傲影 2020-12-05 09:33

Is there a way using HTML/CSS (with relative sizing) to make a row of cells stretch the entire width of the table within which it is contained?

The cells should be e

3条回答
  •  隐瞒了意图╮
    2020-12-05 09:45

    You don't even have to set a specific width for the cells, table-layout: fixed suffices to spread the cells evenly.

    ul {
        width: 100%;
        display: table;
        table-layout: fixed;
        border-collapse: collapse;
    }
    li {
        display: table-cell;
        text-align: center;
        border: 1px solid hotpink;
        vertical-align: middle;
        word-wrap: break-word;
    }
    • foo
      foo
    • barbarbarbarbar
    • baz

    Note that for table-layout to work the table styled element must have a width set (100% in my example).

提交回复
热议问题