文章详情页
css3 - 如何让div中的内容水平居中,垂直居中
浏览:60日期:2023-07-23 18:27:02
问题描述
将内容区域的样式设置成这样,可以解决,可是在编码的时候也会有很多问题。
.element { width: 60px; height: 40px; position: absolute; left: 0; top: 0; right: 0; bottom: 0; margin: auto; /* 有了这个就自动居中了 */ border:1px solid red;}
有其他的方法吗
问题解答
回答1:首先get一个新方法;我一般这样居中.element {
width: 60px; height: 40px;position: absolute; left: 50%; top: 50%;transform:translate(-50%,-50%);border:1px solid red;}
回答2:你需要:CSS布局之-水平垂直居中
回答3:看这里 http://f2e.souche.com/blog/jie-du-cssbu-ju-zhi-shui-ping-chui-zhi-ju-zhong/
标签:
CSS
相关文章:
排行榜
