gpt4 book ai didi

html - 去除流体柔性容器底部的间隙

转载 作者:行者123 更新时间:2023-11-28 02:31:08 25 4
gpt4 key购买 nike

我有一个 3 列的 flex ul 列表,其中包含可变宽度/高度的容器。

当我将 height 设置为 60% 时,它会在底部创建一个间隙。 页脚文本 应该紧靠容器。我需要使用 % 而不是 px 以便它随浏览器大小缩放。

在任何元素上设置 max-height 似乎都不能消除间隙。

containers


https://jsfiddle.net/8ogm45w0/

HTML

<ul class="category">
<li>
<a href="#">
<div class="photo-container">
<img src="https://i.imgur.com/By5S6Rd.jpg">
</div>
<div class="title">Example</div>
</a>
</li>
<li>
<a href="#">
<div class="photo-container">
<img src="https://i.imgur.com/da2NTpb.jpg">
</div>
<div class="title">Example</div>
</a>
</li>
<li>
<a href="#">
<div class="photo-container">
<img src="https://i.imgur.com/RGVB4jY.jpg">
</div>
<div class="title">Example</div>
</a>
</li>
</ul>

<hr />
Footer

CSS

ul.category {
display: flex;
align-items: stretch;
justify-content: space-between;
margin: 0;
padding: 0;
list-style-type: none;
max-height: 300px;
}

ul.category li {
max-width: 32%;
text-align: center;
max-height: 300px;
}

.photo-container {
height: 60%;
max-height: 300px;
overflow: hidden;
}

.photo-container img {
width: 100%;
}

.title {
margin-bottom: 0.5em;
padding: 0.4em;
color: #fff;
font-weight: 700;
background: #000;
}

最佳答案

更新的答案:

我花了很多时间试图解决这个问题,但最后......:)

JSFiddle Demo

body, html {
height: 100%;
width: 100%;
margin: 0;
}

.category {
height: 60%;
display: flex;
flex-direction: row;
justify-content: space-between;
margin: 0;
padding: 0;
list-style-type: none;
background: pink;
}

.category a {
height: 100%;
width: 32%;
}

.photo-container {
height: 100%;
}

.photo-container img {
display: block;
height: 90%;
width: 100%;
}

.title {
height: 10%;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
font-weight: 700;
background: #000;
}

关于html - 去除流体柔性容器底部的间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50710523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com