所以我正在尝试创建一个像这样的网格
我的顶部和底部帖子的大小相同,中间的一个帖子细长,然后自动填充剩余空间。
这是我的代码
<section class="posts-grid">
<article class="post">
<img src="https://blog.flyingsaucer.nyc/hs-fs/hubfs/blog/pitchadri.png?width=1464&name=pitchadri.png" alt="">
<div class="blog-listing-info">
<a href="#">
<h2 class="blog-listing-title">13 things to make your US and UI design much better</h2>
</a>
<p class="blog-listing-tag">Design - 11 min read</p>
</div>
</article>
<article class="post">
<img src="https://blog.flyingsaucer.nyc/hs-fs/hubfs/blog/pitchadri.png?width=1464&name=pitchadri.png" alt="">
<div class="blog-listing-info">
<a href="#">
<h2 class="blog-listing-title">13 things to make your US and UI design much better</h2>
</a>
<p class="blog-listing-tag">Design - 11 min read</p>
</div>
</article>
<article class="post long-post">
<div class="blog-listing-info">
<a href="#">
<h2 class="blog-listing-title">13 things to make your US and UI design much better</h2>
</a>
<p class="blog-listing-tag">Design - 11 min read</p>
</div>
</article>
<article class="post">
<img src="https://blog.flyingsaucer.nyc/hs-fs/hubfs/blog/pitchadri.png?width=1464&name=pitchadri.png" alt="">
<div class="blog-listing-info">
<a href="#">
<h2 class="blog-listing-title">13 things to make your US and UI design much better</h2>
</a>
<p class="blog-listing-tag">Design - 11 min read</p>
</div>
</article>
<article class="post">
<img src="https://blog.flyingsaucer.nyc/hs-fs/hubfs/blog/pitchadri.png?width=1464&name=pitchadri.png" alt="">
<div class="blog-listing-info">
<a href="#">
<h2 class="blog-listing-title">13 things to make your US and UI design much better</h2>
</a>
<p class="blog-listing-tag">Design - 11 min read</p>
</div>
</article>
<article class="post">
<img src="https://blog.flyingsaucer.nyc/hs-fs/hubfs/blog/pitchadri.png?width=1464&name=pitchadri.png" alt="">
<div class="blog-listing-info">
<a href="#">
<h2 class="blog-listing-title">13 things to make your US and UI design much better</h2>
</a>
<p class="blog-listing-tag">Design - 11 min read</p>
</div>
</article>
</section>
css
.posts-grid {
grid-template-areas:
"post post"
"long-post post"
"post post";
grid-template-columns: 15% 1fr;
grid-template-rows: 80px 1fr;
grid-auto-rows: 385px;
grid-column-gap: 23px;
grid-row-gap: 20px;
height: 100vh;
display: grid;
}
.post { grid-area: post; }
.post.long-post { grid-area: long-post !important; }
我已经创建了一个Codepen https://codepen.io/ben_bagley/pen/30272c1f61b4f20c080040f5359bd5f1,但是正如您所看到的,它忽略了这样的好东西
对获得预期效果的任何帮助表示赞赏。
答案 0 :(得分:0)
这是我能做的最好的事,希望对您有所帮助。
HTML:
<section class="posts-grid">
<article class="post">
<img src="https://blog.flyingsaucer.nyc/hs-fs/hubfs/blog/pitchadri.png?
width=1464&name=pitchadri.png" alt="">
<div class="blog-listing-info">
<a href="#">
<h2 class="blog-listing-title">13 things to make your US and UI design
much better</h2>
</a>
<p class="blog-listing-tag">Design - 11 min read</p>
</div>
</article>
<article class="post">
<img src="https://blog.flyingsaucer.nyc/hs-fs/hubfs/blog/pitchadri.png?
width=1464&name=pitchadri.png" alt="">
<div class="blog-listing-info">
<a href="#">
<h2 class="blog-listing-title">13 things to make your US and UI design much better</h2>
</a>
<p class="blog-listing-tag">Design - 11 min read</p>
</div>
</article>
<article class="post">
<img src="https://blog.flyingsaucer.nyc/hs-fs/hubfs/blog/pitchadri.png?width=1464&name=pitchadri.png" alt="">
<div class="blog-listing-info">
<a href="#">
<h2 class="blog-listing-title">13 things to make your US and UI design much better</h2>
</a>
<p class="blog-listing-tag">Design - 11 min read</p>
</div>
</article>
<article class="long-post">
<div class="blog-listing-info">
<a href="#">
<h2 class="blog-listing-title">13 things to make your US and UI design much better</h2>
</a>
<p class="blog-listing-tag">Design - 11 min read</p>
</div>
</article>
<article class="post">
<img src="https://blog.flyingsaucer.nyc/hs-fs/hubfs/blog/pitchadri.png?width=1464&name=pitchadri.png" alt="">
<div class="blog-listing-info">
<a href="#">
<h2 class="blog-listing-title">13 things to make your US and UI design much better</h2>
</a>
<p class="blog-listing-tag">Design - 11 min read</p>
</div>
</article>
<article class="post">
<img src="https://blog.flyingsaucer.nyc/hs-fs/hubfs/blog/pitchadri.png?width=1464&name=pitchadri.png" alt="">
<div class="blog-listing-info">
<a href="#">
<h2 class="blog-listing-title">13 things to make your US and UI design much better</h2>
</a>
<p class="blog-listing-tag">Design - 11 min read</p>
</div>
</article>
<article class="post">
<img src="https://blog.flyingsaucer.nyc/hs-fs/hubfs/blog/pitchadri.png?width=1464&name=pitchadri.png" alt="">
<div class="blog-listing-info">
<a href="#">
<h2 class="blog-listing-title">13 things to make your US and UI design much better</h2>
</a>
<p class="blog-listing-tag">Design - 11 min read</p>
</div>
</article>
</section>
SCSS:
* {
padding: 0px;
margin: 0px;
box-sizing: border-box;
}
.posts-grid {
padding: 10px;
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(5, 1fr);
grid-template-rows: auto;
.post, .long-post {
padding: 10px;
border-radius: 6px;
}
.post:first-child, .long-post + .post {
background: greenyellow;
grid-column-end: span 3;
}
.post + .post + .post {
grid-column-end: span 1;
}
.post {
background: lightblue;
grid-column-start: auto;
grid-column-end: span 2;
}
.long-post {
background: red;
grid-column-end: span 4;
}
img {
width: 100%;
height: auto;
}
}
这是JsFiddle: https://jsfiddle.net/cisco336/ebt0zfvr/