<div class="container">
<span>Grid 网格布局</span>
<div class="grid">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
</div>
</div>
.container {
width: 400px;
margin: 50px auto;
text-align: center;
}
.grid {
width: 200px;
height: 200px;
display: grid;
grid-template-columns: repeat(2, 80px 100px);
grid-template-rows: 100px 200px;
}
.item {
border: 1px solid #000;
margin: 5px;
text-align: center;
}
.item:nth-child(1) {
background: yellow;
}
.item:nth-child(2) {
background: #ece8ce;
}
.item:nth-child(3) {
background: #f2d1ee;
}
.item:nth-child(4) {
background: #bde8f2;
}
.item:nth-child(5) {
background: #51f18c;
}
.item:nth-child(6) {
background: #edae9e;
}
.item:nth-child(7) {
background: #f2d1ee;
}
.item:nth-child(8) {
background: #5ccaffb5;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.