我有一个可能包含大量数据的元素,但我不希望它破坏页面布局,所以我设置了 max-height: 100px
和 overflow: auto
,希望在内容不适合时出现滚动条。
在 Firefox 和 IE7 中一切正常,但 IE8 的行为就像存在 overflow:hidden
而不是 overflow:auto
。
我试过 overflow:scroll
,仍然没有帮助,IE8 只是截断内容而不显示滚动条。将 max-height
声明更改为 height
可以使溢出工作正常,它是 max-height
和 overflow:auto
的组合> 这会破坏事物。
这也被记录为 official bug in the final, release version of IE8
有解决办法吗?现在我使用 height
而不是 max-height
,但它会留下大量空白空间以防数据不多。
最佳答案
这是一个非常讨厌的错误,因为它严重影响了我们在 Stack Overflow 上的 <pre>
代码块,其中有 max-height:600
和 width:auto
.
它在 IE8 的最终版本中被记录为一个错误,没有修复。
http://connect.microsoft.com/IE/feedback/ViewFeedback.aspx?FeedbackID=408759
有一个非常非常 hacky 的 CSS 解决方法:
http://my.opera.com/dbloom/blog/2009/03/11/css-hack-for-ie8-standards-mode
/*
SUPER nasty IE8 hack to deal with this bug
*/
pre
{
max-height: none\9
}
当然还有其他人提到的条件 CSS,但我不喜欢这样,因为这意味着您在每个页面请求中都提供额外的 HTML 垃圾。
关于internet-explorer-8 - IE8 溢出 :auto with max-height,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7707/