如何将网格单元的高度设置为等于兄弟的具体高度?

问题描述 投票:0回答:1
html css css-grid responsive-images subgrid
1个回答
0
投票

我会首先简化你的 HTML 结构,然后更新 CSS,如下所示。

body {
  background-color: tan;
  color: black;
  margin 0;
}

.grid {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: start;
  gap: 20px;
  background-color: antiquewhite;
  width: fit-content;
}

.cell {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

img.icon {
  height: 0;
  min-height: 100%;
}

.cell > p.note {
  width: min-content;
}
<div class=grid>
  <div class="cell">
    <img class="icon" src="https://upload.wikimedia.org/wikipedia/commons/8/8c/Emoji_u1f0cf.svg">
    <p class="note">Matthew Patel</p>
  </div>
  <div class="cell">
    <img class="icon" src="https://upload.wikimedia.org/wikipedia/commons/8/8c/Emoji_u1f0cf.svg">
    <p class="note">Lucas Lee</p>
  </div>
  <div class="cell">
    <img class="icon" src="https://upload.wikimedia.org/wikipedia/commons/8/8c/Emoji_u1f0cf.svg">
    <p class="note">Todd Ingram</p>
  </div>
  <div class="cell">
    <img class="icon" src="https://upload.wikimedia.org/wikipedia/commons/8/8c/Emoji_u1f0cf.svg">
    <p class="note">Roxie Richter</p>
  </div>
</div>

© www.soinside.com 2019 - 2024. All rights reserved.