我正在尝试制作一个固定位置的侧边栏,它下面有一个小标题和一个可滚动的 div。
我的问题是我无法滚动整个 div,所以我看不到其中的所有内容。
这是我的代码,它在 jsfiddle 上。
HTML
<section>
<header>we have some text here
<br>a few lines
<br>doesn't matter
<br>
</header>
<div class="scroll-box">FIRST LINE
<br>a few lines
<br>doesn't matter
<br>we have some text here
<br>a few lines
<br>doesn't matter
<br>we have some text here
<br>a few lines
<br>doesn't matter
<br>we have some text here
<br>a few lines
<br>doesn't matter
<br>we have some text here
<br>a few lines
<br>doesn't matter
<br>we have some text here
<br>a few lines
<br>doesn't matter
<br>we have some text here
<br>a few lines
<br>doesn't matter
<br>we have some text here
<br>a few lines
<br>doesn't matter
<br>we have some text here
<br>a few lines
<br>doesn't matter
<br>we have some text here
<br>a few lines
<br>doesn't matter
<br>we have some text here
<br>a few lines
<br>doesn't matter
<br>we have some text here
<br>a few lines
<br>LAST LINE
<br>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
section {
position: fixed;
top:0;
left: 0;
height: 100%;
width: 300px;
background: red;
}
.scroll-box {
overflow: scroll;
height: 100%;
width: 100%;
background: #eee;
}
Run Code Online (Sandbox Code Playgroud)
谢谢
问题在这里:
.scroll-box {
height:100%;
}
Run Code Online (Sandbox Code Playgroud)
您不能将其设置height
为 100%,因为在占用空间的部分中还有一个标题。
将总额 100% 分配给header
和.scroll-box
section header{
height:30%;
}
.scroll-box {
overflow: auto;
height:70%;
background: #eee;
}
Run Code Online (Sandbox Code Playgroud)
查看演示http://jsfiddle.net/9V45d/8/
归档时间: |
|
查看次数: |
4873 次 |
最近记录: |