<!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>Document</title>
<style>
.box {
/* 首先必须是一个定位的盒子 */
position: absolute;
left: 50%;
top:50%;
transform: translate(-50%, -50%);
width: 200px;
height: 200px;
background-color: deeppink;
}
</style>>
</head>
<body>
<div class="box"></div>
</body>
</html>
让一个定位的盒子水平垂直居中
最新推荐文章于 2024-01-30 22:59:15 发布