2013-04-02 54 views
0

我有一个固定在页面左侧的div,高度为100%。我在里面放置了超出左边div高度的内容。现在,我知道我可以添加overflow:auto以允许用户滚动该div中的内容,但我希望固定div内的内容随页面一起滚动。这是可能的只是CSS?制作固定内容滚动

感谢

的jsfiddle:http://jsfiddle.net/yZmu6/

HTML:

<div id="newsfeed-left"> 
    <div class="green-square"></div> 
    <div class="blue-square"></div> 
    <div class="green-square"></div> 
    <div class="blue-square"></div> 
    <div class="green-square"></div> 
    <div class="blue-square"></div> 
    <div class="green-square"></div> 
    <div class="blue-square"></div> 
    <div class="green-square"></div> 
</div> 

CSS:

body { 
margin: 0px 0px 0px 0px; 
padding: 0px 0px 0px 0px; 
} 

#newsfeed-left { 
position: fixed; 
float: left; 
height: 100%; 
width: 200px; 
padding: 0px 10px 0px 10px; 
border-right: 1px solid rgb(228, 228, 228); 
} 

.green-square { 
margin: 10px 0px 0px 0px; 
height: 200px; 
width: 200px; 
background-color: green; 
} 

.blue-square { 
margin: 10px 0px 0px 0px; 
height: 200px; 
width: 200px; 
background-color: blue; 
} 
+0

没有,这是不可能的只是CSS。我建议你看看这个jQuery插件http://someweblog.com/hcsticky-jquery-floating-sticky-plugin/ –

回答

1

固定div的滚动条是从页面的其余部分分开。虽然这可以用JS完成。

0

这可能不会回答你的问题,或者是你正在寻找的答案,但改变你的CSS使用绝对位置,而不是固定的,使页面正确滚动。

#newsfeed-left { 
    position: absolute; 
    ... 
}