<分区>
<分区>
Possible Duplicate:
How to center DIV in DIV?
听起来很简单但想不通:
如何让固定宽度的 div 在页面上居中?
默认情况下,它向左移动。
halign 已被弃用,但我可以找到替代品。
[更新]
width:800px;left-margin:auto;right-margin:auto:
效果很好。
有没有办法在不设置固定宽度的情况下做到这一点?
最佳答案
试试这个:
<style>
.centered {
margin-left:auto;
margin-right:auto;
}
</style>
<div class="centered">
Some text
</div>
关于html - 我如何居中一个div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7677821/