<!DOCTYPE html>
<html lang="en">
<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>
*{
margin: 0;
padding: 0;
}
html,body{
height:100%;
}
#bg{
height:100%;
background: powderblue;
width: 100%;
}
#inner{
background: blueviolet;
height:240px;
width:240px;
position: absolute;
top:50%;
left:50%;
transform: translate(-120px,-50%);
}
</style>
</head>
<body>
<div id="bg">
<div id="inner"></div>
</div>
</body>
</html>
原文地址:https://www.cnblogs.com/eret9616/p/8668619.html
时间: 2024-10-09 04:23:39