shpasspass
V2EX  ›  问与答

求教一个text-align:center究竟什么时候是居中的?

By shpasspass at 2013 年 6 月 12 日 · 3004 次点击
就是这段html,我已经给.bb进行text-align:center了,但为什么无效呢?
最混乱的就是我自己写html时加text-align:center,有时候会居中,有时候不会居中,到底什么样的情况下,text-align:center才会生效呢?


<!DOCTYPE html>
<style>
.aa{
float:left;
}
.bb{
text-align:center;
}
</style>

<div class="aa">

<div class="bb">
我真的想居中,但就是无法居中
</div>

</div>
2 条回复  •  1970-01-01 08:00:00 +08:00
guchengf
   1
guchengf  
   2013 年 6 月 12 日   ❤️ 1
没有参考物怎么居中,两端得有边界才行啊
给.aa 加上 width:100%;
再看效果
cutehalo
   2
cutehalo  
   2013 年 6 月 12 日
float以后div的宽度就不是100%了
© 2026 V2EX · 27ms · 3.9.8.5