1. 程式人生 > >元素水平垂直居中

元素水平垂直居中

doc div tom 水平 charset ack round ctype style

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
div{
position: absolute;

background: red;

/*
width:200px;
height:300px;
left:0;
top:0;
right:0;
bottom:0;
margin:auto; */

/* width:200px;
height:300px;
left:50%;
top:50%;
margin-left:-100px;
margin-top:-150px; */

/* width:30%;
height:50%;
left:50%;
top:50%;
transform:translateX(-50%) translateY(-50%); */

display:flex;
width:200px;
height:200px;
align-item:center;
justify-content:center;

}

</style>
</head>
<body>
<div></div>
</body>
</html>

元素水平垂直居中