<!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>
</head>
<body>
<div class="father">
<div class="son">
</div>
</div>
</body>
</html>
<style>
.father{
width: 300px;
height: 300px;
background-color: blue;
display: flex;
}
.son{
width: 200px;
height: 200px;
background-color: yellow;
margin: auto;
}
</style>
父元素设置display:flex,子元素设置margin:auto。可以实现水平垂直居中
最新推荐文章于 2024-04-09 17:52:46 发布