我有一个包含流体宽度/高度容器的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;
}
答案 0 :(得分:0)
我花了很多时间试图解决这个问题,但最后......:)
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;
}