【问题标题】:scroll bar go behind the div滚动条在 div 后面
【发布时间】:2014-08-05 14:50:50
【问题描述】:

萨拉姆,

我想做一个如下的 HTML 布局:

+----------------------+-----+
|       upSide         |     |
|----------------------|     |
|                      |right|
|                      |side |
|                      |     |
|      mainSide        |     |
|                      |     |
|                      |     |
+----------------------+-----+

类似这样的事情:

<div id="rightSide"></div>
<div id="mainFrame">
    <div id="upside"></div>
    <div id="mainSide"></div>
</div>

我希望#upSide 在#mainSide 上方,换句话说,当您滚动#mainFrame 时,#mainSide 中的元素在#upSide 后面可见,而#upSide 的背景是透明的(例如 background-颜色:rgba(0,0,0,0.35))。

问题是当我设置如下内容时:

#upSide{
    position:fixed;
    width: 80%;
}
#rightSide{
    width:20%;
    float:right;
    position:relative;
}
#mainFrame{
    height:100%;
    overflow:auto;
}

一切都是真的,但滚动条(在#mainFrame 中)位于#upSide 后面。 您对这种情况有什么建议?

【问题讨论】:

    标签: html css layout css-float


    【解决方案1】:

    滚动条位于 #upSide 后面,因为您添加了 position:fixed。

    试试这样的。

    <html>
    <head>
        <style>
        #upSide{
            height:200px;
            width: 80%;
            background:blue;
        }
        #mainSide{
            height:800px;
            width: 80%;
            background:green;
        }
        #rightSide{
            width:20%;
            height:800px;
            float:right;
            position:relative;
            background:red;
        }
        #mainFrame{
            height:800px;
            width: 80%;
            overflow:auto;
            background:yellow;
        }
        </style>
    </head>
    <body>
        <div id="rightSide"></div>
        <div id="mainFrame">
            <div id="upside"></div>
            <div id="mainSide"></div>
        </div>
    
    </body>
    

    【讨论】:

    • 我希望#upSide 贴在页面顶部。它应该始终可见。即使用户向下滚动。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-19
    • 1970-01-01
    • 2022-01-04
    • 2013-12-19
    • 2019-07-17
    • 1970-01-01
    • 2019-06-26
    相关资源
    最近更新 更多