CSS布局
大约 1 分钟
1. 实现水平居中和垂直居中
.parent {display: grid;place-items: center;}
<html>
<div class="layout-parent-1" ><div>:)</div></div>
</html>
<style>
.layout-parent-1 {
display: grid;
place-items: center;
background: lightblue;
width: 100%;
height: 200px;
resize: both;
overflow: auto;
}
.layout-parent-1>div {
padding: 0.5rem;
border-radius: 10px;
border: 1px solid red;
background: lightpink;
font-size: 2rem;
text-align: center;
}
</style>
2. 可解构的自适应布局
<html>
<div class="layout-parent-2" >
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</html>
<style>
.layout-parent-2 {
display: flex;
flex-wrap: wrap;
resize: both;
overflow: auto;
}
.layout-parent-2>div {
flex: 0 1 300px;
flex: 1 1 300px;
border: 1px solid red;
background: lightpink;
font-size: 2rem;
text-align: center;
}
</style>