我正在尝试实现一种布局,第一行有 2 列,之后有 3 列,就像附加的图像一样。我正在使用 css 网格
。
到目前为止,这是我的代码
body {
background: #161616;
color: #bdbdbd;
font-weight: 300;
height: 100vh;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
font-family: Helvetica neue, roboto;
}
h1 {
font-weight: 300;
}
a {
color: white;
text-decoration: none;
color: #4d4d4d;
}
.container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-column-gap: 15px;
grid-row-gap: 15px;
}
.feature__item {
background-color: #C4C4C4;
padding: 15px;
color: #4d4d4d;
}
.feature__item:first-of-type{
grid-column-start: 1;
grid-column-end: 3;
}
.feature__item:nth-child(2) {
}
<div class="container">
<div class="feature__item">
<h5>Heading</h5>
<p>12</p>
<a href="#" class="btn btn-primary">Discover More</a>
</div>
<div class="feature__item">
<h5>Heading</h5>
<p>34</p>
<a href="#" class="btn btn-primary">Discover More</a>
</div>
<div class="feature__item">
<h5>Heading</h5>
<p>56</p>
<a href="#" class="btn btn-primary">Discover More</a>
</div>
<div class="feature__item">
<h5>Heading</h5>
<p>78</p>
<a href="#" class="btn btn-primary">Discover More</a>
</div>
<div class="feature__item">
<h5>Heading</h5>
<p>90</p>
<a href="#" class="btn btn-primary">Discover More</a>
</div>
</div>
这是关于 Playcode 的工作示例
您需要将网格分成 6 列才能跨越其中的 3 或 2 列
body {
background: #161616;
color: #bdbdbd;
font-weight: 300;
height: 100vh;
margin: 0;
display: flex;
/*
align-items: center;
justify-content: center;
*/
text-align: center;
font-family: Helvetica neue, roboto;
}
h1 {
font-weight: 300;
}
a {
color: white;
text-decoration: none;
color: #4d4d4d;
}
.container {
/* instead , align/justify */ margin:auto;
display: grid;
grid-template-columns:repeat(6,1fr);
grid-column-gap: 15px;
grid-row-gap: 15px;
}
.feature__item {
background-color: #C4C4C4;
padding: 15px;
color: #4d4d4d;
grid-column : span 2;
}
.feature__item:first-of-type,
.feature__item:nth-child(2) {
grid-column: span 3;
}
<div class="container">
<div class="feature__item">
<h5>Heading</h5>
<p>12</p>
<a href="#" class="btn btn-primary">Discover More</a>
</div>
<div class="feature__item">
<h5>Heading</h5>
<p>34</p>
<a href="#" class="btn btn-primary">Discover More</a>
</div>
<div class="feature__item">
<h5>Heading</h5>
<p>56</p>
<a href="#" class="btn btn-primary">Discover More</a>
</div>
<div class="feature__item">
<h5>Heading</h5>
<p>78</p>
<a href="#" class="btn btn-primary">Discover More</a>
</div>
<div class="feature__item">
<h5>Heading</h5>
<p>90</p>
<a href="#" class="btn btn-primary">Discover More</a>
</div>
</div>
我是一名优秀的程序员,十分优秀!