html - 表格单元格看起来像忽略固定宽度

标签 html css

我的构造:

<div style="display: table;">
    <div style="display: table-cell; width: 50px; background-color: red;">a</div>
    <div style="display: table-cell; width: 100%; background-color: green;">...</div>
    <div style="display: table-cell; width: 50px; background-color: red;">a</div>
</div>

http://jsfiddle.net/5PgzT/

边缘列应该保持 50px 宽度,仍然像我没有设置任何东西一样

最佳答案

一、父<div>没有明确的 width , 另外你可能需要使用 table-layout: fixed; 还有:

<div style="display: table; width: 100%; table-layout: fixed;">
    <div style="display: table-cell; width: 50px; background-color: red;">a</div>
    <div style="display: table-cell; width: 100%; background-color: green;">...</div>
    <div style="display: table-cell; width: 50px; background-color: red;">a</div>
</div>

WORKING DEMO

关于html - 表格单元格看起来像忽略固定宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21913520/

相关文章:

html - Twitter Bootstrap 导航列表中的长文本跨越容器边界

html - Magento 的自定义 header

css - 为什么 DIV 中的 SVG 与 BUTTON 元素中的 SVG 对齐方式不同

javascript - 获取在运行时加载的元素的 innerhtml

javascript - CSS 有效但不能动态应用

javascript - 在 css 中设置事件状态的问题

html - IE9、表格和显示: block

由数据库填充的 PHP 下拉列表将使用 javascript

javascript - getBoundingClientRect 检测可见性

javascript - Z 索引不起作用