使已定位元素水平,垂直居中的方法

来源:互联网 发布:世界最流行的编程语言 编辑:程序博客网 时间:2024/04/29 12:02

//方法1:

div{

positon:absolute;

width:100px;

height:100px;

border:1px solid red;

top:0;

left:0;

right:0;

bottom:0;

margin:auto;

}

//方法2:

div{

positon:absolute;

width:100px;

height:100px;

border:1px solid red;

top:50%;

left:50%;

margin-left:-50px;

margin-right:-50px;

}

//方法3:

div{

positon:absolute;

width:100px;

height:100px;

border:1px solid red;

top:50%;

left:50%;

transform:translate(-50%,-50%);

}

transformtranslate(-50%,-50%);
阅读全文
0 0