文章标题 div 居中的三种方法

来源:互联网 发布:淘宝客qq群拉人 编辑:程序博客网 时间:2024/06/10 03:59

html中实现水平居中的方法如下:
HTML部分代码如下:

css代码如下:
方法(1):
.test {
width:100px;
height:100px;
background:#000;
position:absolute;
left:0;
top:0;
margin-left:-50px;
margin-top:-50px;
}
方法(2):
.test {
width:120px;
height:120px;
position:absolute;
margin:auto;
left:0;
right:0;
top:0;
bottom:0;
}
方法(3):
.test {
width:100px;
height:100px;
position:absolute;
left:50%;
top:50%;
transform:translate(-50%,-50%);
-webkit-transform:translate(-50%,-50%);
-moz-transform:translate(-50%,-50%);
-ms-transform:translate(-50%,-50%);
-o-transform:translate(-50%,-50%);
}

0 0
原创粉丝点击