位置:相对和溢出:自动问题,但不能在包含元素上使用位置:相对! :-(

发布于 2024-08-15 17:11:03 字数 784 浏览 2 评论 0原文

我有一个页面,我需要在 html 和 body 标签内使用溢出:自动,因为我有一个位置:固定元素,为此我必须在 IE 中使用位置:绝对(因此,溢出:自动以摆脱 IE漏洞)。

这一点已排序。

但现在我的问题是我的页面上有其他position:relative 元素。当我放置 *html, body{ Overflow : auto;} 时,那些相对定位的元素表现得很奇怪,并且由于另一个 IE bug(overflow:auto 和position:relative)而在 IE 中得到了修复。

我被告知,在一般情况下,此错误的解决方法是在“包含元素”中包含position:relative。但这是不可能的,因为我的包含元素需要 IE 中的position:absolute 才能使固定元素起作用。

我该如何解决这个问题?


* html , body { height:100%; overflow : auto;}
* body #fixedelement {position:absolute;} /* for IE */

body > #fixedelement {position:fixed;} /*for firefox etc*/

#relative{
    /* I need to use this but putting position:relative to html or body
    seems not possible coz i need #fixedelement to work in IE */
    position:relative;
}

请帮忙

I have a page where I need to use overflow:auto inside html and body tags because I have a position : fixed element, for which I have to use position : absolute in IE (and thus, overflow:auto to get rid of the IE bug).

This bit is sorted.

But now my problem is I have other position: relative elements on my page. And the moment I put *html, body{ overflow : auto;} those relatively positioned elements behave strangely and kinda get fixed in IE due to another IE bug (the overflow:auto and position:relative one).

The workaround for this bug in a general case I am told is to include position:relative in the "containing element". But that is not possible since my containing element needs a position:absolute in IE to make the fixed element work.

How do I go about solving this?


* html , body { height:100%; overflow : auto;}
* body #fixedelement {position:absolute;} /* for IE */

body > #fixedelement {position:fixed;} /*for firefox etc*/

#relative{
    /* I need to use this but putting position:relative to html or body
    seems not possible coz i need #fixedelement to work in IE */
    position:relative;
}

Please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋千易 2024-08-22 17:11:03

有一个技巧,它允许您将绝对定位的元素放入相对元素中。 您可能会发现它很有用。

There is a trick for it, which allows you to put absolute-positioned elements inside a relative element. You may find it useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文