<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>利用translate实现盒子居中案例</title>
<style>
div{
position:relative;
width:500px;
height:500px;
background-color:pink;
}
p{
position:absolute;
left:50%;
top:50%;
width:200px;
height:200px;
background-color:purple;
transform: translate(-50%,-50%);
/* margin-left:-100px;
margin-top:-100px; */
}
</style>
</head>
<body>
</body>
<div>
<p></p>
</div>
</html>
实现效果;

491

被折叠的 条评论
为什么被折叠?



