设置div的css为
margin:0auto;text-align:center;
效果(中间的div是居中的):
效果(中间的div是居中的):
居中
例子代码
<div style="width:400px;height:100px;border: 1px solid blue;">
<div style="width:300px;height:80px;margin:0 auto;text-align:center;border: 1px solidblue;">
<p>
居中
</p>
</div>
</div>
本文介绍了一种使用CSS实现div元素水平居中的方法。通过设置外部div宽度,并利用margin:0 auto属性使内部div居中显示。同时,还展示了如何在居中的div内设置文字居中。
1202

被折叠的 条评论
为什么被折叠?



