<!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>居中</title>
<style>
body>div{width: 400px;height: 400px;background: yellow;margin-bottom: 20px;}
div div{width: 200px;height: 200px;background: red;}
body>div:nth-child(1){display: flex;}
div:nth-child(1) div{margin: auto;
}
</style>
</head>
<body>
<div>
<div>1</div>
</div>
</body>
</html>
运行结果
来源:CSDN
作者:你知道歌谣吗?
链接:https://blog.csdn.net/weixin_43392489/article/details/103837865