扩大网格区域而不折叠行

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

我想做 .item8 拓展 .item2.item3. 谁能帮帮我?

当我做 .item81 / 2 / span 2 / span 5,然后它就只平坦到第一排。

就像这样,我想让.item8扩展到.item2和.item3上。

enter image description here

.grid-container {
  display: grid;
  grid-template-columns: auto auto auto auto auto auto;
  grid-gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

.grid-container>div {
  background-color: rgba(255, 255, 255, 0.8);
  text-align: center;
  padding: 20px 0;
  font-size: 30px;
}

.item8 {
  grid-area: 1 / 2 / span 2 / span 4;
}

.item1 {
  grid-area: 1 / 1 / 4 /1;
}
<div class="grid-container">
  <div class="item1">1</div>
  <div class="item2">2</div>
  <div class="item3">3</div>
  <div class="item4">4</div>
  <div class="item5">5</div>
  <div class="item6">6</div>
  <div class="item7">7</div>
  <div class="item8">8</div>
  <div class="item9">9</div>
  <div class="item10">10</div>
  <div class="item11">11</div>
  <div class="item12">12</div>
  <div class="item13">13</div>
</div>
css css-grid
1个回答
0
投票

你没有为行或网格容器定义高度。这意味着行将默认为 grid-auto-rows: auto (基于内容的高度),而网格容器将基于网格项的 自动排位算法轨迹尺寸算法.

保持简单。在容器上定义一个高度,或者为行定义一个高度。

.grid-container {
  display: grid;
  grid-template-columns: repeat(6, auto);
  grid-auto-rows: 100px; /* new */
  grid-gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

.grid-container>div {
  background-color: rgba(255, 255, 255, 0.8);
  text-align: center;
  padding: 20px 0;
  font-size: 30px;
}

.item8 {
  grid-area: 1 / 2 / span 2 / span 5; /* adjustment */
}

.item1 {
  grid-area: 1 / 1 / 4 / 1;
}
<div class="grid-container">
  <div class="item1">1</div>
  <div class="item2">2</div>
  <div class="item3">3</div>
  <div class="item4">4</div>
  <div class="item5">5</div>
  <div class="item6">6</div>
  <div class="item7">7</div>
  <div class="item8">8</div>
  <div class="item9">9</div>
  <div class="item10">10</div>
  <div class="item11">11</div>
  <div class="item12">12</div>
  <div class="item13">13</div>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.