【发布时间】:2015-10-09 01:33:22
【问题描述】:
我有一个响应式设计,侧边栏占 25%,内容占 75%。我的问题是当我滚动页面时,侧边栏没有固定并且不会随着页面向下滚动。
我尝试将其设置为 position:fixed,但随后我失去了对内容的整个响应百分比。
我怎样才能做到这两点?
小提琴: http://codepen.io/anon/pen/oXMmOz
HTML
<div class="container max-width">
<div class="sidebar"></div>
<div class="content"></div>
</div>
CSS
.max-width {
max-width: 1300px;
margin: 0 auto;
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
margin-top: 54px;
}
.sidebar {
background-color: red;
width: 25%;
padding-top: 0;
position: absolute;
left: 0;
top: 0;
bottom: 0;
}
.content {
background-color: black;
width: 75%;
margin-left: 25%;
padding-top: 15px;
}
@media(max-width: 768px) {
.sidebar {
left: -200px;
position: fixed;
}
.content {
width: 100%;
margin-left: auto;
}
}
【问题讨论】:
标签: jquery html css responsive-design css-float