您的位置:首页 > 其它

web网页中各种margin布局居中效果 水平居中 垂直居中 水平垂直居中

2018-03-14 22:05 337 查看
页面中元素居中效果分为三种情况,1.水平居中,2.垂直居中,3.水平垂直居中
下面代码视图层统一代码结构:<div class="father">
<div class="son"></div>
</div>1.水平居中:
应用场景:整体网站居中,文字排版居中
css代码:.father{
width: 100%;
}
.son{
width:800px;
height: 60px;
background: #ccc;
margin: auto;
}2.垂直居中:
css代码:.father{
width: 100%;
height:300px;
writing-mode: vertical-lr;
background: orange;
}
.son{
width:80%;
height: 100px;
background: #f2f2f2;
margin: auto;
}
3.水平居中:.father{
position:absolute;
top: 0;left: 0;bottom: 0;right: 0;
background: rgba(0,0,0,.5);
}
.son{
position: absolute;
top: 0;left: 0;bottom: 0;right: 0;
width:300px;
height: 300px;
background: #f2f2f2;
margin: auto;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: