gpt4 book ai didi

css - 第一行有 2 个感冒,然后使用 css 网格在每行中有 3 列

转载 作者:太空宇宙 更新时间:2023-11-03 20:25:18 25 4
gpt4 key购买 nike

我正在尝试实现一种布局,第一行有 2 列,之后有 3 列,就像附加的图像一样。我正在使用 css 网格

i want to achieve this layout

到目前为止,这是我的代码

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>

关于css - 第一行有 2 个感冒,然后使用 css 网格在每行中有 3 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56853527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com