如何在使用CSS网格布局时删除此空白?

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

我只是从速成班学习如何使用CSS网格布局。在修改grid-template-columns属性时,在我无法摆脱的猫图像之一下出现了空白。

The space

这是我的HTML:

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.gallery {
  display: grid;
  grid-template-columns: 200px 200px 1fr;
}

.gallery img {
  width: 100%;
}
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />

  <main>
    <div class="gallery">
      <img src="https://placeimg.com/640/480/animals" alt='' />
      <img src="https://placeimg.com/640/480/arch" alt='' />
      <img src="https://placeimg.com/640/480/nature" alt='' />
      <img src="https://placeimg.com/640/480/people" alt='' />
      <img src="https://placeimg.com/640/480/tech" alt='' />
    </div>
</main>

有人可以帮我解决这个问题吗?

css css-grid
1个回答
0
投票

将第三张图像分成三行:

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.gallery {
  display: grid;
  grid-template-columns: 200px 200px 1fr;
}

.gallery img {
  width: 100%;
}

.gallery img:nth-child(3) {
  grid-row: span 3;
}
<div class="gallery">
  <img src="https://placeimg.com/640/480/animals" alt='' />
  <img src="https://placeimg.com/640/480/arch" alt='' />
  <img src="https://placeimg.com/640/480/nature" alt='' />
  <img src="https://placeimg.com/640/480/people" alt='' />
  <img src="https://placeimg.com/640/480/tech" alt='' />
</div>
© www.soinside.com 2019 - 2024. All rights reserved.