css - 是否可以将滚动条从容器中取出到文档中?

标签 css

.cnt
  overflow: auto

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

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

附言为什么内容末尾有1px的线?

最佳答案

你可以使用面具让 body 溢出: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>

关于css - 是否可以将滚动条从容器中取出到文档中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44700227/

相关文章:

css - 位置 :fixed inside of an iframe

jquery - 在 Liferay 中使用 jQuery UI 布局插件

html - 响应式表格,无法将 thead 和 tbody 对齐

html - 在不颠倒输入顺序的情况下向右浮动搜索栏?

html - Md卡填充

HTML:标题标签的百分比是多少?

CSS flexible padding-divs with centered text inside, max-padding

html - 具有特定类的元素的选择器,如果它是其父元素的唯一子元素?

html - 如何使 div 扩展以适应可用的垂直空间?

css - 如何使 Bootstrap 图标与标签中的文本内联显示?