我有一个有趣的设计要实现,我尝试使用CSS网格来编码它。起初,我尝试使用Isotope JS来获得相同的布局,但没有任何成功。我最接近的设计是使用CSS网格。
我总共有7个从for loop
动态生成的项目。它们需要被分成3列和3行。前两列应该各有两个项目,最后一列应该有其余的3个项目。前两列也有一点奇怪的间距。我设法使第一列,但没有成功与中间列垂直对齐的项目。
下面是我需要实现的布局的图像:
以下是我到目前为止所尝试的:
.pr-soft-masonry-layout {
display: grid;
grid-gap: 20px;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(2, 1fr);
align-items: center;
}
.grid-item-1 {
grid-row: 1 / 3;
}
.grid-item-2 {
grid-column: 1 / 2;
grid-row: 3/-1;
justify-self: end;
margin-top: -300px;
}
.grid-item-3 {
grid-row: 1 / 2;
grid-column: 2 / 3;
}
.grid-item-4 {
grid-column: 2 / 2;
}
.grid-item-5 {
grid-row: 1 / 2;
grid-column: 3 / 3;
}
/* .grid-item-6 {
grid-row: 3 / -1;
} */
.grid-item-7 {
grid-column: 3 / 3;
}
.pr-soft-masonry-card {
/* height: 280px; */
padding: 30px;
border-radius: 30px;
/* width: 425px; */
}
.pr-soft-masonry-title {
font-family: 'Garnett Medium';
font-style: normal;
font-weight: 500;
font-size: 44px;
line-height: 53px;
}
.pr-soft-masonry-featured-number {
font-family: 'Garnett Medium';
font-style: normal;
font-weight: 500;
font-size: 90px;
line-height: 108px;
margin-bottom: 20px;
}
.pr-soft-masonry-card p {
font-family: 'Rza';
font-style: normal;
font-weight: 505;
font-size: 20px;
line-height: 23px;
}
<div class="pr-soft-masonry-layout grid">
<div style="background-color: #FFB79B; width: 427px;" class="pr-soft-masonry-card grid-item-1">
<div style="#5E3313" class="pr-soft-masonry-title">
A sneak peak of the data you’ll discover in the study
</div>
</div>
<div style="background-color: #5E3313; width: 312px;" class="pr-soft-masonry-card grid-item-2">
<div style="color: #FDDAAB" class="pr-soft-masonry-featured-number">
75%
</div>
<p style="color: #FFF;">marks the satisfaction score among professionals who utilize Chat GPT for work</p>
</div>
<div style="background-color: #E4E1FD; width: 426px;" class="pr-soft-masonry-card grid-item-3">
<div style="color: #4C3FD5" class="pr-soft-masonry-featured-number">
44%
</div>
<p style="color: #000;">of PR Pros find the media database to be the most valuable solution</p>
</div>
<div style="background-color: #92C34B; width: 426px;" class="pr-soft-masonry-card grid-item-4">
<div style="color: #E8F5D4" class="pr-soft-masonry-featured-number">
#1
</div>
<p style="color: #FFF;">threat posed by AI according to PR practitioners are manipulation and fake news</p>
</div>
<div style="background-color: #FDDAAB; width: 314px;" class="pr-soft-masonry-card grid-item-5">
<div style="color: #FF7E4D" class="pr-soft-masonry-featured-number">
#1
</div>
<p style="color: #5E3313;">problem: getting journalists to respond</p>
</div>
<div style="background-color: #E8F5D4; width: 426px;" class="pr-soft-masonry-card grid-item-6">
<div style="color: #92C34B" class="pr-soft-masonry-featured-number">
76%
</div>
<p style="color: #000;">foresee critical thinking to be a paramount PR skill for the future</p>
</div>
<div style="background-color: #FF7E4D; width: 314px;" class="pr-soft-masonry-card grid-item-7">
<div style="color: #FDDAAB" class="pr-soft-masonry-featured-number">
48%
</div>
<p style="color: #000;">of PR practitioners struggle with tight budgets</p>
</div>
</div>
1条答案
按热度按时间s8vozzvw1#
我同意@ralph.m的评论,你需要更多的行。在这个代码片段中,我使用了10行。请注意,每个网格项至少跨越三行。