使用transform实现元素的水平垂直居中
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<style type="text/css">
#outer{
width: 500px;
height: 500px;
background-color: aquamarine;
margin:0 auto;
position: relative;
}
#inner{
position: absolute;
width: 200px;
height: 200px;
background-color: red;
left: 50%;
top: 50%;;
transform: translate(-50%,-50%);
}
</style>
</head>
<body>
<div id="outer">
<div id="inner"></div>
</div>
</body>
</html>
显示效果: