CSS绝对DIV导致其他绝对DIV问题

发布于 2024-09-03 07:27:16 字数 902 浏览 2 评论 0原文

我已经实现了一个聊天脚本,它需要一个绝对定位的 DIV 来包裹页面内容。

这是为了确保聊天窗口保持在底部。

问题是,由于这个主包装器的绝对定位,所有其他绝对定位的元素(例如 Jquery 自动完成、日期选择器等)现在随页面上下滚动。

下面是 HTML 的示例:

<body>
<div id="main_container">
    <div id="content">Elements like Jquery Autocompletes, Datepickers with absolute positioned elements in here</div>
</div>

DIV“main_container”样式如下所示:

#main_container {
    width:100%;
    background-color:#ffffff; /* DO NOT REMOVE THIS; or you'll have issue w/ the scrollbar, when the mouse pointer is on a white space */
    overflow-x: hidden;
    overflow-y: scroll;
    height:100%;    /* this will make sure that the height will extend at the bottom */
    position:absolute; /* container div must be absolute, for our fixed bar to work */
}

我希望有一个简单的修复,因为聊天脚本太好了,无法摆脱。

谢谢,

蒂姆

I have implemented a chat script which requires an absolutely positioned DIV to be wrapped around the pages content.

This is to ensure the chat windows stay at the bottom.

The problem is that because of the absolute positioning of this main wrapper, all other absolutely positioned elements (eg. Jquery Auto-completes, datepicker's etc) now scroll up and down with the page.

Here is an example of the HTML:

<body>
<div id="main_container">
    <div id="content">Elements like Jquery Autocompletes, Datepickers with absolute positioned elements in here</div>
</div>

The DIV "main_container" style looks like this:

#main_container {
    width:100%;
    background-color:#ffffff; /* DO NOT REMOVE THIS; or you'll have issue w/ the scrollbar, when the mouse pointer is on a white space */
    overflow-x: hidden;
    overflow-y: scroll;
    height:100%;    /* this will make sure that the height will extend at the bottom */
    position:absolute; /* container div must be absolute, for our fixed bar to work */
}

I hope there is a simple fix as the chat script is too good to get rid of.

Thanks,

Tim

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

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

发布评论

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

评论(1

没︽人懂的悲伤 2024-09-10 07:27:16
  1. 您最好将您想要的内容保留在相对于视口的固定位置,position:fixed;。
  2. 背景颜色似乎是一个糟糕的黑客。
  3. 您可以使周围元素(主)位置:相对,而无需为其提供顶部/左侧/右侧/底部属性以及位置:绝对内的每个“固定”元素,因为它们现在将相对于具有位置:相对的父级。
  4. 如果这些都不起作用,请发布更多代码,尤其是“随页面上下滚动的元素”的定位。还不清楚“页面”是什么意思。身体?网页?视口?主要内容?
  1. You are probably better off making what you want to stay in a fixed position relative to the viewport, position:fixed;.
  2. The background colour seems like a bad hack.
  3. You can make the sorrounding element (main) position:relative without giving it top/left/right/bottom properties and each "fixed" element within, position:absolute, as they will now be relative to the parent which has position:relative.
  4. If none of these work, post more code, especially for the positioning of your "elements that scroll up and down with the page". It's also unclear what you mean with "page". Body? Html? Viewport? main's contents?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文