首页 > 代码库 > 上下左右居中模块(上下左右垂直居中)

上下左右居中模块(上下左右垂直居中)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>上下左右居中模块</title>
<style>
*{
margin: 0;
padding: 0;
list-style: none;
}
body{
background-color: #000;
}
.lanren{
position: fixed;
left: 50%;
top: 50%;
-webkit-transform:translate(-50%,-50%);
-moz-transform:translate(-50%,-50%);
-o-transform:translate(-50%,-50%);
-ms-transform:translate(-50%,-50%);
transform:translate(-50%,-50%);
}
.square{
width: 114px;
height: 114px;
border: 5px solid white;
box-sizing: border-box;
background-color: red;
}
</style>
</head>
<body>
<div class="lanren">
<div class="square"></div>
</div>
</body>
</html>

效果

技术分享

 

上下左右居中模块(上下左右垂直居中)