繁体   English   中英

将容器始终放在最上面

[英]Positioning a container always on top

我有一个插件,其中提供了一个简单的div容器,并且该插件通过javascript在容器内创建了各种dom元素。 插件创建的基本结构如下所示:

Wrapper Div (Position:Relative)
   - Left Container (Position: Absolute)
        - Left Top sub-container (Position: Absolute)
   - Right Container (Position: Relative)
        - Right Top sub-container (Position: Absolute)
        - Right Sub-Container frame with absolute items (Position: Relative)

这是我为插件创建的完全相同的结构创建的小提琴: http : //jsfiddle.net/FsYt8/

我在这里面临的问题是,当内容溢出时,可以使用鼠标滚轮滚动内容(如小提琴一样)。 但是,当我向下滚动时,我希望小提琴中的上方左右两个子容器(红色/蓝色条)颜色保持在顶部本身,而不是随内容向下滚动。

该插件在container-right-frame div内创建dom元素,并将元素定位为绝对(然后按照container-right的top / left定位)。 如何实现以上两个小节的固定定位?

使标题固定并相应地定位它们:

http://jsfiddle.net/QYCra/

向下移动列的初始高度,以便它们在标题下开始:

.frame {width:924px;height:300px;position:relative;overflow-x:hidden;}
.axis-left {width:303px;height:34px;position:fixed; top:0; background-color:blue;z-index:2;}
.axis-right {width:615px;height:34px;position:fixed; top:0; left:310px; background-color:red;z-index:2;}
.container-left {height:340px;width:303px;top:30px; left:0px;position:absolute;background-color:green;z-index:1;overflow:hidden;}
.container-right {height:340px;width:615px;top:30px; left:304px;position:relative;overflow:hidden;background-color:yellow;z-index:1;}

您可以固定红色和蓝色DIV,然后将其浮动到左侧。 右DIV的左边界将如下调整DIV的x轴位置:

.frame {width:924px;height:300px;position:relative;overflow-x:hidden;}
.axis-left {float:left;width:303px;height:34px;position:fixed;background-color:blue;z-index:2;}
.axis-right {float:left;margin-left:305px;width:303px;height:34px;position:fixed;background-color:red;z-index:2;}
.container-left {height:340px;width:303px;left:0px;position:absolute;background-color:green;z-index:1;overflow:hidden;}
.container-right {height:340px;left:304px;position:relative;overflow:hidden;}
.container-right-frame{
    position:relative;top:34px;background-color:yellow;z-index:1;width:615px;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM