小div在大div中垂直居中,以及div在页面垂直居中

时间:2022-08-14 06:37:57

<html>
<head>
<title>淘宝 2faner</title>
<style type="text/css">
.big{
width: 800px;
height: 500px;
background: #333;
position:absolute;
left: 50%;
top: 50%;
margin-left:-400px; 
margin-top: -250px;

}
.small{
width: 400px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
margin-left:-200px; 
margin-top: -100px;
background: #fff;
}
</style>
</head>
<body>
<div class="big">
<div class="small">
 
</div>
</div>
</body>
</html>