【盒子水平垂直居中的三种(四种)方式】
效果
方法一:利用margin:auto
margin: auto;和 margin-top: ;搭配使用
<style>
* {
padding: 0;
margin: 0;
}
.parent {
position: fixed;
width: 900px;
height: 600px;
background-color: aqua;
}
.children {
margin: auto;
margin-top: 150px;
width: 300px;
height: 300px;
background-color: pink;
}
</style>
</head>
<body>
<div class="parent">
<div class