<!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>Document</title>
<style>
/* div{
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
width: 100px;
height: 100px;
background-color: red;
} */
/* div{
top: 50%;
left:50%;
transform: translate(-50%,-50%);
position: absolute;
width: 100px;
height:100px;
background-color: gold;
} */
div{
position: absolute;
top: 50%;
left:50%;
margin-left: -50px;
margin-top: -50px;
width: 100px;
height:100px;
background-color: blue;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
盒子水平垂直居中的三种方式(单个div)
最新推荐文章于 2024-07-25 09:24:40 发布