我如何使用display:grid
所以它只针对.entry
或.post
元素并排除档案标题和分页?
(archive-description
和pagination
跨越内容div的全宽)
.content {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-gap: 20px;
}
<main class="content">
<div class="archive-description">Archive Title</div>
<article class="post entry">This is a post</article>
<article class="post entry">This is a post</article>
<article class="post entry">This is a post</article>
<li class="pagination">Previous & Next Entry</li>
</main>
你可以使用archive-description
跨越网格的列跨越pagination
和grid-column: span 3
。
请参阅下面的演示 - 添加边框以进行说明(也使li
成为div
以获得有效标记):
.content {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-gap: 20px;
position: relative;
border: 1px solid green;
}
.archive-description, .pagination {
grid-column: span 3;
text-align: center;
}
main > * {
border: 1px solid;
}
<main class="content">
<div class="archive-description">Archive Title</div>
<article class="post entry">This is a post</article>
<article class="post entry">This is a post</article>
<article class="post entry">This is a post</article>
<div class="pagination">Previous & Next Entry</div>
</main>