从流体柔性容器底部移除间隙

时间:2018-06-06 00:01:39

标签: html css css3 flexbox

我有一个包含流体宽度/高度容器的3列flex ul列表。

当我将height设置为60%时,会在底部创建一个间隙。 footer text应该正好对抗容器。我需要使用%而不是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;
}

1 个答案:

答案 0 :(得分:0)

更新回答:

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

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;
}