将网格项跨越到CSS Grid的整个宽度

问题描述 投票:4回答:1

我如何使用display:grid所以它只针对.entry.post元素并排除档案标题和分页?

archive-descriptionpagination跨越内容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>

https://jsfiddle.net/haymanpl/rb0hqb7g/2/

css html5 css3 css-selectors css-grid
1个回答
8
投票

你可以使用archive-description跨越网格的列跨越paginationgrid-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>
© www.soinside.com 2019 - 2024. All rights reserved.