【问题标题】:Show horizontal scrollbar at the bottom of screen, not at the bottom of element在屏幕底部显示水平滚动条,而不是在元素底部
【发布时间】:2020-03-30 02:06:41
【问题描述】:

我的网站内容很长 - 所以网站必须是垂直可滚动的。但是,页面底部也有水平滚动的 div。不幸的是,在用户向下滚动之前,该元素的水平滚动条是不可见的。有没有办法在屏幕底部显示水平滚动条? Here 就是例子。

.container {
  overflow-y: auto;
  overflow-x: hidden;
}

.content {
  background-color: lightblue;
  height: 5rem;
}

.scrollable-content {
  background-color: lightgreen;
  height: 100vh;
  overflow-x: auto;
  width: 100%;
}

.wide-content {
  width: 150vw;
}
<div class="container">
  <div class="content">
    Div which is not horizontally scrollable
  </div>
  <div class="scrollable-content">
    Div which is horizontally scrollable
    <div class="wide-content">
      Some wide content
    </div>
  </div>
</div>

【问题讨论】:

  • 我也有同样的问题,想知道您是否找到了解决方案?

标签: html css scrollbar


【解决方案1】:

我把scrollable-content改成了这个:

.scrollable-content {
  background-color: lightgreen;
  height: 89vh;
  width: 1000%;
}

和正文:

body {
 overflow: hidden;
}

希望对你有帮助

【讨论】:

    【解决方案2】:

    您必须在您的 CSS 中添加一些 -webkit-scrollbar 选择器以每次显示滚动条。看下面的例子:

    .scrollable-content::-webkit-scrollbar {
        -webkit-appearance: none;
    }
    .scrollable-content::-webkit-scrollbar:horizontal {
        height: 11px;
    }
    .scrollable-content::-webkit-scrollbar-thumb {
        border-radius: 8px;
        border: 2px solid white;
        background-color: rgba(0, 0, 0, .5);
    }
    .scrollable-content::-webkit-scrollbar-track { 
        background-color: #fff; 
        border-radius: 8px; 
    } 
    
    
    .container {
      overflow-y: auto;
      overflow-x: hidden;
    }
    
    .content {
      background-color: lightblue;
      height: 5rem;
    }
    
    .scrollable-content {
      background-color: lightgreen;
      height: 30vh;
      overflow-x: auto;
      width: 100%;
    }
    
    .wide-content {
      width: 150vw;
    }
    <div class="container">
       <div class="content">
            Div which is not horizontally scrollable
       </div>
       <div class="scrollable-content" style="width:500px; overflow-x:scroll; border:dotted 1px; white-space: nowrap;padding-bottom:10px;">
        	Div which is horizontally scrollable
          <div class="wide-content">
               Some wide content
          </div>
       </div>
    </div>

    我希望解决方案如你所想

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-28
      • 2017-09-22
      • 2021-03-19
      • 2013-07-19
      • 2014-12-12
      • 2014-10-01
      相关资源
      最近更新 更多