css - 如何在尊重 Internet Explorer 11 中的最大高度继承的同时滚动固定标题下的内容?

标签 css internet-explorer overflow internet-explorer-11

我有一个最大高度的容器。我想在其中放置一个标题和一个滚动体。这在大多数浏览器中都很简单,但我在 IE11 上苦苦挣扎。使用 max-height: inherit;.scroll div 及其滚动条延伸到其父级下方(参见 IE11 中的代码片段)

It's trivial using flexbox instead ,但是IE11有一个bug需要改变body的显示才能解决。但我不能那样做。

有没有办法让 .scroll 在没有 flexbox 的情况下在 IE11 中正确滚动,同时尊重容器上的 max-height 功能?

div {
  border: 1px solid #DDD;
}
.container {
  max-height: 150px;
  overflow: hidden;
}
.header {
  height: 40px;
}
.scroll {
  max-height: inherit;
  overflow: auto;
}
  <div class="container">
    <div class="header">
      header
    </div>
    <div class="scroll">
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll</div>
    </div>
  </div>

最佳答案

这似乎不是 IE 的特定问题,我在 Chrome 上也看到了同样的问题。 您的容器高度为 150 像素(因为它来自第三方框架,我们无法更改此数字),因此“滚动”元素的高度应为 150 像素 - 40 像素 = 110 像素。让我们设置它而不是“继承”:

div {
  border: 1px solid #DDD;
}
.container {
  max-height: 150px;
  overflow: hidden;
}
.header {
  height: 40px;
}
.scroll {
  max-height: 110px;
  overflow: auto;
}
  <div class="container">
    <div class="header">
      header
    </div>
    <div class="scroll">
      <div>scroll first</div>
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll</div>
      <div>scroll last</div>
    </div>
  </div>

一切正常(我已经在 IE 和 Chrome 上测试过)

关于css - 如何在尊重 Internet Explorer 11 中的最大高度继承的同时滚动固定标题下的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38534628/

相关文章:

css - Chrome 偶尔会渲染一个没有样式表的页面几秒钟

html - IE 错误将内容向下和向右推送 - 如何解决?

java - 为什么2147483647 + 1实际上是-2147483648?

html - 将 overflow-x 应用于 CSS grid-column 元素似乎也适用 overflow-y

html - 自定义样式后,Bootstrap Navbar 在移动 View 中无法正常工作

javascript - 如果 jQuery.show() 在上一个事件中使用,jQuery 不会隐藏 DIV

CSS 转换在 Firefox 上无法正常工作

html - CSS 在所有浏览器中都不起作用

css - 内容背景被截断

html - 是否可以更改 SSRS 中 Web 服务界面的外观?