【发布时间】:2018-07-01 00:40:12
【问题描述】:
我有一个包含流体宽度/高度容器的 3 列 flex ul 列表。
当我将height 设置为60% 时,它会在底部创建一个间隙。 footer text 应该正对着容器。我需要使用% 而不是px,所以它会随着浏览器的大小而缩放。
在任何元素上设置max-height 似乎并不能消除差距。
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;
}
【问题讨论】: