<div style="display: inline-block; margin: 0 auto;">
<input id="abc" type="button" value="button" />
</div>
我尝试使用上面的代码来设置等于它的内容的宽度,然后将它居中:0 auto;
但它在任何浏览器上都不适用于我。有什么建议吗?
顺便说一句,当我设置width属性时,它工作得很好。
<div style="width: 10em; margin: 0 auto;">
<input id="abc" type="button" value="button" />
</div>
发布于 2012-02-16 22:55:13
显示:表格;也会将它放在中心位置:
CSS:
.button{
display: table;
margin: 0 auto;
}
HTML:
<div class="button">
<input id="abc" type="button" value="button" />
< /div>
注意:使用内联样式是一种不好的做法。
发布于 2012-02-16 22:48:36
既然您要求DIV是inline-block
,那么text-align: center;
就是答案。
<div style="text-align: center;">
<div style="display: inline-block; text-align: left;">
<input id="abc" type="button" value="button" />
</div>
</div>
发布于 2015-05-21 07:50:37
试一试
body {text-align: center;}
https://stackoverflow.com/questions/9313276
复制相似问题