启用在指定div中滚动?

时间:2018-08-16 22:55:08

标签: html css css3

我有以下情况。容器c具有固定属性。它始终是100%的高度。不动。

容器b具有动态高度。

容器a(正文)根本无法显示滚动条。

问题:如何强制body中的滚动条消失,但容器b中的滚动条出现?谢谢!

.a {
  display: flex;
  height: 300px;
}

.b,
.c {
  width: 50%;
}

.b {
  background: blue;
  height: 600px;
  overflow-y: scroll;
}

.c {
  background: green;
  height: 300px;
  position: fixed;
  right: 0;
}
<div class='a'>
  <div class='b'>
  </div>
  <div class='c'>
  </div>
</div>

1 个答案:

答案 0 :(得分:1)

归功于SirExotic

您的.b容器需要的内容超过b的高度才能激活滚动条。

body {
  overflow-y: hidden; /* added */
}

.a {
  display: flex;
  height: 300px;
}

.b,
.c {
  width: 50%;
}

.b {
  background: blue;
  height: 600px;
  overflow-y: scroll;
}

.b-content {
   min-height: 800px;
 }

.c {
  background: green;
  height: 300px;
  position: fixed;
  right: 0;
}
<div class='a'>
  <div class='b'>
    <div class="b-content">
      here I am
    </div>
  </div>
  <div class='c'>
  </div>
</div>