相同大小的表格单元格以填充包含表格的整个宽度 [英] Equal sized table cells to fill the entire width of the containing table

查看:17
本文介绍了相同大小的表格单元格以填充包含表格的整个宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用 HTML/CSS(具有相对大小)使一行单元格拉伸包含它的表格的整个宽度?

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 equal widths and the outer table size is also dynamic with <table width="100%">.

目前如果我没有指定固定大小;单元格只是自动调整大小以适应其内容.

Currently if I don't specify a fixed size; the cells just autosize to fit their contents.

推荐答案

你甚至不必为单元格设置特定的宽度,table-layout: fixed 就足以让单元格均匀分布.

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;
}

<ul>
  <li>foo<br>foo</li>
  <li>barbarbarbarbar</li>
  <li>baz</li>
</ul>

请注意,要使 table-layout 工作,表格样式元素必须设置宽度(在我的示例中为 100%).

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

这篇关于相同大小的表格单元格以填充包含表格的整个宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆