IE和绝对定位div
此问题仅在 IE 中出现。考虑以下 HTML:
<html>
<body>
<div style='position:absolute;left:1em;right:1em;top:1em;bottom:1em;overflow:auto;>
Put more than a full screen of text in here. It *should* create a scroll inside the div.
In IE, it stretches the div out vertically.
<div>
<body>
<html>
如果在 div 中放入大量文本,IE 会将 div 拉伸到声明的“底部”之外。我知道它在做什么。它认为页面底部是所有文本呈现后的页面底部。我希望底部是可见窗口的底部。所以,我想要一个位于窗口中心的 div。有没有一些弱智的 hack 可以让 IE 理解 CSS 的基本概念?
This problem is only in IE. Consider the following HTML:
<html>
<body>
<div style='position:absolute;left:1em;right:1em;top:1em;bottom:1em;overflow:auto;>
Put more than a full screen of text in here. It *should* create a scroll inside the div.
In IE, it stretches the div out vertically.
<div>
<body>
<html>
If you put a ton of text in the div, IE will stretch the div out beyond the declared "bottom". I know what it is doing. It considers the bottom of the page to be the bottom of the page after all of the text has been rendered. I want bottom to be the bottom of the visible window. So, I want to have a div that is centered inside the window. Is there some retarded hack to make IE comprehend the basic concept of CSS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当使用绝对位置冲突时,不要忘记“创建例外”下的 IE6 修复该文章中针对 IE5 和 IE6 的标头。
When using conflicting absolute positions don't forget the fix for IE6 under the 'Creating the exception for IE5 and IE6' header in that article.
您可以尝试使用条件注释添加
overflow:auto;
(仅适用于 IE)。You could try using a conditional comment to add
overflow:auto;
for IE only.