【发布时间】:2018-02-19 14:34:13
【问题描述】:
我的目标是在一个父 div 中嵌套 5 个 div。 每个 div 都一样宽,并且并排。
这是我的 HTML:
<div style="margin-left: auto; margin-right: auto; width: 80%;">
<div style="display: table-row;">
<div style="display: table-cell; text-align: center; width: 20%;">Left</div>
<div style="display: table-cell; text-align: center; width: 20%;">Left</div>
<div style="display: table-cell; text-align: center; width: 20%;">Left</div>
<div style="display: table-cell; text-align: center; width: 20%;">Left</div>
<div style="display: table-cell; text-align: center; width: 20%;">Left</div>
</div>
</div>
并排功能有效,但宽度无效。这一切都只是挤到左边。任何想法为什么?
【问题讨论】:
-
您的 div 的样式为
table-cell,因此它的作用类似于表格。试试看这里:stackoverflow.com/questions/10525744/css-table-cell-equal-width -
你只需要把
"display:table"放在第一个div中。
标签: html