滚动条与固定div的内容重叠

时间:2014-03-30 21:01:17

标签: html css

我在右侧有一个固定的div(购物车列表)。如果项目太多,则会出现滚动条。问题是,它部分涵盖了固定的div。当滚动条出现时,如何让div向左推,这样它就不会被覆盖?

Scollbar Problem

我的CSS:

/* sidebar-right */
#sidebar-wrapper-right {
    margin-left: -250px;
    right: 0;
    width: 250px;
    background: #F5F5F5;
    position: fixed;
    height: 100%;
    overflow-y: auto;
    z-index: 1000;
    top: 60px;
}

.sidebar-nav-right {
    position: absolute;
    top: 0;
    width: 250px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-nav-right li {
    line-height: 40px;
    text-indent: 20px;
}

.sidebar-nav-right li a {
    color: #555;
    display: block;
    text-decoration: none;
}

.sidebar-nav-right li a .item-count {
    margin-top: 10px;
    padding-left: 0;
    margin-right: 5px;
}

.sidebar-nav-right li a:hover {
    color: #000;
    background: rgba(255,255,255,0.8);
    text-decoration: none;
}

.sidebar-nav-right > .sidebar-brand {
    height: 65px;
    line-height: 60px;
    font-size: 18px;
}

.sidebar-nav-right > .sidebar-brand a {
    color: #000;
}

.sidebar-nav-right > .sidebar-brand a:hover {
    color: #fff;
    background: none;
}

#sidebar-wrapper-right .sidebar-nav-right .sidebar-right-trash {
    display: inline;
    margin-right: -10px;
    top: 12px;
}

#sidebar-wrapper-right .sidebar-nav-right .sidebar-right-trash:hover {
    background: none;
}

和HTML:

<div id="sidebar-wrapper-right">
    <ul class="sidebar-nav-right">
        <li class="sidebar-brand">[Shopping Cart]</li>
        <li>
            <a href="#" class="glyphicon glyphicon-trash sidebar-right-trash pull-left"></a>
            <a href="market/#">[X] <span class="badge pull-right item-count">5</span></a>
        </li>
        <li>
            <a href="#" class="glyphicon glyphicon-trash sidebar-right-trash pull-left"></a>
            <a href="market/#">[X] <span class="badge pull-right item-count">10</span></a>
        </li>
        <li>
            <a href="#" class="glyphicon glyphicon-trash sidebar-right-trash pull-left"></a>
            <a href="market/#">[X] <span class="badge pull-right item-count">10</span></a>
        </li>
        <li>
            <a href="#" class="glyphicon glyphicon-trash sidebar-right-trash pull-left"></a>
            <a href="market/#">[X] <span class="badge pull-right item-count">10</span></a>
        </li>
        <li>
            <a href="#" class="glyphicon glyphicon-trash sidebar-right-trash pull-left"></a>
            <a href="market/#">[X] <span class="badge pull-right item-count">10</span></a>
        </li>
        <li>
            <a href="#" class="glyphicon glyphicon-trash sidebar-right-trash pull-left"></a>
            <a href="market/#">[X] <span class="badge pull-right item-count">10</span></a>
        </li>
        <li>
            <a href="#" class="glyphicon glyphicon-trash sidebar-right-trash pull-left"></a>
            <a href="market/#">[X] <span class="badge pull-right item-count">10</span></a>
        </li>
        <hr class="sidebar-seperator">
    </ul>
</div>

3 个答案:

答案 0 :(得分:1)

从div元素中删除overflow-y:auto;并将overflow-y:auto; height:100%添加到ul元素。 http://jsfiddle.net/gLdCg/

答案 1 :(得分:0)

将列表放入一个几乎看不见的小桌子中,并将一些细胞填充物放入侧面。这样就可以将列表保留在屏幕的旁边。或者你可以非常具体地将表放入一个不会受到影响的位置:

//PUT the and right pixels in the number that the scroll bar is generally.
<IMG STYLE="position:absolute; right:(NUMBER OF PIXELS AWAY FROM THE RIGHT)px>

我个人会使用绝对位置,但那只是我。

乐意帮忙!

答案 2 :(得分:0)

向侧边栏添加修复高度

#sidebar-wrapper-right {
    margin-left: -250px;
    right: 0;
    width: 250px;
    background: #F5F5F5;
    position: fixed;
    height: 300px; /*or max-height:300px;*/
    /*height: 100%;*/
    overflow-y: auto;
    z-index: 1000;
    top: 60px;
}