【发布时间】:2015-05-31 13:47:53
【问题描述】:
我正在从将 div 用作按钮转换为实际按钮,现在我需要让按钮填满容器的整个宽度。
代码:
.container {
background-color: #ddd;
padding: 10px;
max-width: 500px;
margin-left: auto;
margin-right: auto;
}
.button {
display: block;
background-color: #bbb;
margin: 10px;
padding: 10px
}
<div class="container">
<div class="button">
Fills the full width
</div>
<button class="button">
Does not fill the full width
</button>
</div>
将display:block 添加到.button 不起作用(尽管我确定这一定是答案的一部分?),left: 0; right: 0 也不起作用。 width: 100% 有点工作,但它忽略了容器的填充属性并使按钮离容器的右侧太近。
这里是 JSFiddle:http://jsfiddle.net/mn40mz2n/
【问题讨论】:
标签: css