【发布时间】:2022-07-04 16:37:50
【问题描述】:
希望有人能指出我正确的方向。我有一个简单的网格照片库(图像的大小和纵横比不匹配)。
我试图弄清楚如何调整 的高度,以便为
- 如果我将
设置为 'height: 100%;',
会溢出 。 - 如果我设置 'height: auto;',风景图片会在
上方留下太多空间。
有没有办法正确调整 的大小,使其填充
将 上方并设置
<figure>
<a href="/photo/349">
<img src="/images/77.jpeg">
</a>
<figcaption>
<a href="/tag/dog">dog</a>
</figcaption>
</figure>
<figure>
<a href="/photo/251">
<img src="/images/104.jpeg">
</a>
<figcaption>
<a href="/tag/tink">tink, </a>
<a href="/tag/dog">dog, </a>
<a href="/tag/human">human</a>
</figcaption>
</figure>
<figure>
<a href="/photo/361">
<img src="/images/88.jpeg">
</a>
<figcaption>
<a href="/tag/adam">adam, </a>
<a href="/tag/dio">dio, </a>
<a href="/tag/dog">dog, </a>
<a href="/tag/human">human, </a>
<a href="/tag/car">car</a>
</figcaption>
</figure>
section {
display: grid;
column-gap: var(--colGap);
row-gap: calc(var(--colGap) * 1.618);
grid-template-columns: repeat(auto-fill, var(--photoW));
justify-content: center;
}
figure {
width: var(--photoW);
height: calc(var(--photoW) * 1.618);
padding: 5px;
border: 2px solid var(--accent);
border-bottom-left-radius: 8px;
border-bottom-right-radius: 8px;
}
img {
width: 100%;
height: auto;
object-fit: cover;
}
figcaption {
padding: .3em;
margin-left: -7px;
width: var(--photoW);
color: var(--dark);
font-size: 18px;
text-align: center;
}
【问题讨论】: