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;
}
下面代码视图层统一代码结构:<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;
}
相关文章推荐
- [转]CSS网页布局:div水平居中的各种方法
- CSS网页布局DIV水平居中的各种方法
- CSS网页布局:div水平居中的各种方法
- 【转】CSS网页布局DIV水平居中的各种方法
- CSS网页布局:div垂直居中的各种方法
- CSS网页布局:div水平居中的各种方法
- 网页常见布局,让图片在div中,垂直居中,水平居中
- CSS水平居中,垂直居中以及各种布局方式
- CSS网页布局DIV垂直居中的各种方法
- DIV布局的设置(水平或者垂直居中)
- css布局网页水平居中常用方法
- 水平居中和transform: translateY(-50%) 实现元素垂直居中效果
- 【前端攻略】最全面的水平垂直居中方案与flexbox布局
- CSS 样式水平居中和垂直居中的各种方法
- 各种情况的水平垂直居中
- CSS布局:图片在DIV中上下左右居中(水平和垂直都居中)
- 如何在页面布局中实现元素水平+垂直居中
- 小tip: margin:auto实现绝对定位元素的水平垂直居中
- web居中布局-水平居中
- 各种水平垂直居中