DIV居中:利用绝对定位加负边距
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DIV居中
</title>
<style>
#div1{
width:
300px;
height:
300px;
background-color:
yellow;
position:
relative;
}
#div2{
width:
200px;
height:
200px;
background-color:
antiquewhite;
position:
absolute;
left:
50%;
margin-left: -
100px;
top:
50%;
margin-top: -
100px;
}
</style>
</head>
<body>
<div id="div1">
<div id="div2">
</div>
</div>
</body>
</html>
转载请注明原文地址: https://www.6miu.com/read-51002.html