溢出:滚动不显示整个div

时间:2013-11-01 19:30:58

标签: html css html5 css3

我正在尝试制作一个固定位置的侧边栏,它有一个小标题和一个可滚动的div。

我的问题是我无法滚动整个div,因此我看不到其中的所有内容。

这是我的代码和here it is on 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>

CSS

    section {
    position: fixed;
    top:0;
    left: 0;
    height: 100%;
    width: 300px;
    background: red;
}
.scroll-box {
    overflow: scroll;
    height: 100%;
    width: 100%;
    background: #eee;
}

由于

2 个答案:

答案 0 :(得分:3)

问题在于:

.scroll-box {
   height:100%;
}

您无法将height设置为100%,因为您在占用空间的部分中也有一个标题。

将总计100%分配给header.scroll-box

section header{
  height:30%;
}
.scroll-box {
  overflow: auto;
  height:70%;
  background: #eee;
}

观看演示 http://jsfiddle.net/9V45d/8/

答案 1 :(得分:0)

您正在使用类滚动框将div的大小设置为屏幕大小的100%。标题占用了页面上的空间,因此滚动区域被裁剪。

如果您将css更改为:

.scroll-box {
    overflow: scroll;
    height: 91%;
    width: 100%;
    background: #eee;
}

您将能够看到整个滚动框和所有值。所以你需要在标题和滚动之间分配100%