香太郎 3星
共回答了365个问题采纳率:90.6% 评论
让div中的文字水平居中很容易,只需要将属性text-align设置为center或将margin设置为0 aotuo就可以了。而让div中的文字垂直居中还是要费一番周折的。
1.首先如果div中只有一行文字,那么可以通过将lineheight属性和height属性的值设为一样来实现。
2.如果div中有多行文字时,则需要通过position属性来实现垂直居中的效果了,代码如下:html:<div id="box"><div id="sub"><div id="content">垂直居中</div></div></div>css: #box{border:1px solid #000;background:#f00;position:relative;height:400px;width:400px} #sub{position:absolute;top:50%} #content{border:1px solid #fff;position:relative;top:-50%;color:#000}
1小时前
猜你喜欢的问题
5个月前1个回答
5个月前1个回答
5个月前1个回答
5个月前2个回答
5个月前1个回答
5个月前2个回答
热门问题推荐
1个月前2个回答
2个月前3个回答
1个月前2个回答
1个月前1个回答
3个月前3个回答
1个月前1个回答
4个月前2个回答
3个月前1个回答
2个月前1个回答