CSS实现垂直水平居中
2016-09-03 10:51
302 查看
其中内容居中:
1.利用line-height属性
.style1{
width:200px;
height:200px;
line-height:200px;
text-align:center;
background:red;
}
2.利用display:table-cell属性。
.style2{
display:table-cell;
vertical-align:middle;
text-align:center;
width:200px;
height:200px;
background:red;
}
整块居中:
1.使用position:fixed或position:absolute属性,设置left、top、margin-left、margin-top。
.style3{
position:absolute;/position:fixed;/
width:200px;
height:200px;
top:50%;
left:50%;
margin-top:-100px;
margin-left:-100px;
background:red;
}
2.使用position:fixed或position:absolute属性,设置margin:auto。
.style4{
position:absolute;/position:fixed;/
width:200px;
height:200px;
top:0;
right:0;
bottom:0;
left:0;
margin:auto;
background:red;
}
CSS垂直水平居中有很多种,目前学习到这几种,欢迎大神们给出意见建议或补充~
1.利用line-height属性
.style1{
width:200px;
height:200px;
line-height:200px;
text-align:center;
background:red;
}
2.利用display:table-cell属性。
.style2{
display:table-cell;
vertical-align:middle;
text-align:center;
width:200px;
height:200px;
background:red;
}
整块居中:
1.使用position:fixed或position:absolute属性,设置left、top、margin-left、margin-top。
.style3{
position:absolute;/position:fixed;/
width:200px;
height:200px;
top:50%;
left:50%;
margin-top:-100px;
margin-left:-100px;
background:red;
}
2.使用position:fixed或position:absolute属性,设置margin:auto。
.style4{
position:absolute;/position:fixed;/
width:200px;
height:200px;
top:0;
right:0;
bottom:0;
left:0;
margin:auto;
background:red;
}
CSS垂直水平居中有很多种,目前学习到这几种,欢迎大神们给出意见建议或补充~
相关文章推荐
- CSS实现水平/垂直自适应浏览器居中【转】
- css实现div内图片的垂直、水平居中
- 翻译:盘点8种CSS实现垂直居中水平居中的绝对定位居中技术
- css实现图片水平垂直居中
- CSS实现DIV水平居中和上下垂直居中
- DIV水平垂直居中css实现代码
- 纯css实现div中单行文字,多行文字,嵌套div垂直水平居中问题
- 纯css实现文字及图片水平垂直居中
- css实现图片在div中水平和垂直居中(但图片宽高要小于div宽高)
- css实现水平、垂直居中的几种方法
- 使用CSS实现垂直水平居中
- CSS实现未知内容高度的垂直水平居中(改良版)
- CSS实现图片水平垂直居中于DIV
- 寥寥几行CSS:实现某个div在网页中垂直水平居中呢
- 用div+css实现水平垂直居中
- 纯css实现小图片在大容器内水平垂直居中resize
- css实现水平居中和垂直居中及其浏览器兼容性
- 使用纯CSS实现未知尺寸的图片(但高宽都小于200px)在200px的正方形容器中水平和垂直居中。
- CSS:实现某个div在网页中垂直水平居中
- css实现div水平、垂直居中