是否可以将容器中的滚动条带到文档中?

时间:2017-06-22 13:03:27

标签: css

.cnt
  overflow: auto

https://codepen.io/DTX/pen/qjjyEe

我希望它看起来像图像上的滚动条: Img

P.S。为什么内容结尾有1px行?

2 个答案:

答案 0 :(得分:1)

您可以使用面具让身体溢出:https://codepen.io/gc-nomade/pen/jwwpXQ



.wrap {
  height: 80vh;
  margin: 10vh 10vw;
  width: 80vw;
}

.wrap:before {/* here comes the mask hidding edges with a white shadow */
  content: "";
  position: fixed;
  top: 10vh;
  bottom: 10vh;
  left: 10vw;
  width: 80vw;
  border: solid 1px;
  box-shadow: 0 0 0 10vw white;
  pointer-events: none;/* will not catch pointer-events and will let pointer-events occurs within .wrap */
}

.sidebar {
  text-align: center;
  background: rgba(170, 170, 170, 0.7);
  height: 80vh;
  position: fixed;
  width: 20vw;
  left: 10vw;
}

.sidebar button {
  margin: 5px;
}

main {
  background: #FFAB91;
  margin-left: 20vw;
}

header {
  background: #ccc;
  height: 30px;
  text-align: center;
}

header span {
  background: #aaa;
  display: inline-block;
  height: 12px;
  margin-top: 9px;
  vertical-align: top;
  width: 90px;
}

.hide {
  display: none;
}

.item {
  height: 100px;
  background: #ddd;
  margin: 20px;
}

.cnt {
  padding-bottom: 10vh
}

<div class="wrap">
  <div class="sidebar">Sidebar</div>
  <main>
    <header><span>  </span></header>
    <div class="cnt">
      <div class="item"><a href="">click me</a> or select me </div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
    </div>
  </main>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您可以通过从overflow: auto移除.wrap并添加额外的叠加来隐藏溢出的内容来欺骗:

https://codepen.io/anon/pen/PjjBxE