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.

推荐答案

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>

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

Html相关问答推荐

连续的相同 colored颜色 单元格应位于同一列、网格框中

如何在所有屏幕大小下使带有背景图像的伪元素作为标题的衬底?

Vutify中看不见的V行

布局更改时的转换

如何将tmap按钮和图例更改为位于页脚后面?

如何在小屏幕中制作水平滚动div

悬停表格单元格文本时,使元素的字体大小更大,同时保持表格单元格的高度不变

网格布局中的组件

如何保持块扩展以填充视口?

将箭头图标添加到工具提示包装器时遇到问题

如何在CSS伪类函数中使用复合 Select 器:host-context()

对齐列表项内的文本,使其不在元素装饰下

如何让一个 div 始终贴在容器的边缘?

HTML画布放大/缩小算法与CSS(图像处理)

导航丸被选中(活动),但内容未显示.怎么会?

Tailwind CSS 复选框样式不起作用

正确使用视频作为背景

Bootstrap 5 网格问题,div 向下转义

将固定/绝对伪元素放置在相对 div(具有滚动条)内,始终位于底部

悬停时倾斜效果错误