css - 在 ie11 中使用 flexbox 在图像下方留空

标签 css flexbox

所以我试图回答 this question通过仅使用 display:flex (试图了解 flex 的所有细微差别)但我遇到了一个问题,即在 ie11 中,图像下方似乎有一个空间 - 它看起来好像图像-holder 正在占用原始图像的高度。

是否有一个简单的修复方法,使图像支架与其中的图像一样高?

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

body {
  display: flex;
  max-height: 100%;
}

.wrapper {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  height: 100%;
  max-height: 100%;
  width: 100%;
  overflow: hidden;
}

header {
  background: grey
}

main {
  display: flex;
  flex-direction: row;
  flex: 1;
  background: blue
}

.column {
  width: 50%;
  padding: 10px;
  box-sizing: border-box;
  display: flex;
  flex: 1;
  flex-direction: column;
}

.column:first-child {
  background: yellow;
}

.column:last-child {
  background: green;
}

.image-holder {
  margin-bottom: 10px;
  background: orange;
}

.image {
  width: 100%;
  display: block;
  height: auto;
}

.scrollable-content {
  flex: 1;
  background: grey;
  position: relative;
  height: 10px;
}

.firefox-scroller {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  overflow: auto;
  padding: 20px;
  box-sizing:border-box;
}
<div class="wrapper">
  <header>header</header>
  <main>
    <div class="column">
      <div class="image-holder">
        <img src="http://l7.alamy.com/zooms/19704c162b4446c984a50bfdb49b45ac/a-colour-image-taken-on-a-cloudy-dawn-of-the-town-of-saint-malo-from-g1k27a.jpg" alt="" class="image">
      </div>
      <div class="scrollable-content">
        <div class="firefox-scroller">
          <h1>I am trying to do:</h1>
          <h3>1) make these gray div height 100% till bottom</h3>
          <h3>2) When content is more then this gray div should be scrollable or else not</h3>
          <p>
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
          </p>

        </div>
      </div>
    </div>
    <div class="column">
      <div class="image-holder">
        <img src="http://l7.alamy.com/zooms/19704c162b4446c984a50bfdb49b45ac/a-colour-image-taken-on-a-cloudy-dawn-of-the-town-of-saint-malo-from-g1k27a.jpg" alt="" class="image">
      </div>

    </div>
  </main>
</div>

我试过使用 flex-shrink 和 flex-basis,但似乎无法摆脱那个空间。愚蠢的,即!

最佳答案

您可以在 IE 中使用最小高度强制重排:

例子:

body,
html {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
}
body {
  display: flex;
  max-height: 100%;
}
.wrapper {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  height: 100%;
  max-height: 100%;
  width: 100%;
  overflow: hidden;
}
header {
  background: grey
}
main {
  display: flex;
  flex-direction: row;
  flex: 1;
  background: blue
}
.column {
  width: 50%;
  padding: 10px;
  box-sizing: border-box;
  display: flex;
  flex: 1;
  flex-direction: column;
}
.column:first-child {
  background: yellow;
}
.column:last-child {
  background: green;
}
.image-holder {
  margin-bottom: 10px;
  background: orange;
  min-height: 1%;
  /* added for IE */
}
.image {
  width: 100%;
  display: block;
  height: auto;
}
.scrollable-content {
  flex: 1;
  background: grey;
  position: relative;
  height: 10px;
}
.firefox-scroller {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  overflow: auto;
  padding: 20px;
  box-sizing: border-box;
}
<div class="wrapper">
  <header>header</header>
  <main>
    <div class="column">
      <div class="image-holder">
        <img src="http://l7.alamy.com/zooms/19704c162b4446c984a50bfdb49b45ac/a-colour-image-taken-on-a-cloudy-dawn-of-the-town-of-saint-malo-from-g1k27a.jpg" alt="" class="image">
      </div>
      <div class="scrollable-content">
        <div class="firefox-scroller">
          <h1>I am trying to do:</h1>
          <h3>1) make these gray div height 100% till bottom</h3>
          <h3>2) When content is more then this gray div should be scrollable or else not</h3>
          <p>
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
          </p>

        </div>
      </div>
    </div>
    <div class="column">
      <div class="image-holder">
        <img src="http://l7.alamy.com/zooms/19704c162b4446c984a50bfdb49b45ac/a-colour-image-taken-on-a-cloudy-dawn-of-the-town-of-saint-malo-from-g1k27a.jpg" alt="" class="image">
      </div>

    </div>
  </main>
</div>

关于css - 在 ie11 中使用 flexbox 在图像下方留空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40176830/

相关文章:

html - 如何去除页面中间的白条?

css - 如何使用 Angular Material 确保边距相等? (md-grid-list md-grid-tile md-rowspan)

javascript - 动态排列 md-dialog 标签

html - 为什么溢出-y : hidden creating a horizontal scroll bar in my flex layout?

html - 如果垂直滚动条可见,Chrome 中的 Flexbox 元素高度错误

React-native:弹性布局中未考虑边距

jquery - 调整大小时,div 的宽度恢复正常

jquery - 如何使用jquery在文本框中添加背景图像

html - ie7 和 google adsense 绝对定位

html - CSS z-index 仅适用于阴影