在网页上,我有一排提交按钮。居中使用CSS的宽度相等的表格式布局?
- 按钮的该行应该在网页
- 每个按钮应该是一样宽的最宽的按钮(即没有固定的/硬编码键宽度)上居中。
这很容易用<table>
完成,但随着人们不断告诉我那些对你不好,我想知道这是否可以用CSS来完成。所以,我已经试过了display: table
和table-cell
CSS类,但无论是按钮不能获得平等的宽度,或最长的按钮的标题被剪掉:
.button-row {
display: table;
margin: auto;
table-layout: fixed;
}
.button-row button {
white-space: nowrap;
display: table-cell;
width: 50%;
}
<div class="button-row" >
<button>Short caption</button>
<button>A much longer caption</button>
</div>
事实上,它看起来正确的在IE中,但不在Chrome和Firefox。这里是我的两个表 - 和CSS-尝试小提琴:
如果可能的话,我想摆脱width: 50%
设置,因为按钮的数量可能会有所不同,但是这很容易计算。
非常感谢,这工作!任何想法,如果可以做到这一点,而不指定每个按钮的百分比? – Sphinxxx 2014-10-29 23:39:08