水平滚动不在元素末尾

问题描述 投票:0回答:1

有一个高度为150vh的#horizontal_scroll元素。它有一个比父元素宽 2 倍的子元素。元素#horizontal_scroll 的水平滚动显示在元素的末尾(如果将页面滚动到底部)。是否可以不在元素末尾(150vh)而是在屏幕末尾(100vh)显示此滚动?

enter image description here

#horizontal_scroll {
  background: grey;
  width: 50vw;
  height: 150vh;
  overflow: auto;
}
#horizontal_scroll div {
  width: 100vw;
}
<div id="horizontal_scroll">
<div></div>
</div>

html css
1个回答
0
投票

为了获得所需的行为,水平滚动出现在屏幕末尾(100vh)而不是元素末尾(150vh)

body {
  margin: 0;
  height: 200vh; /* To allow enough space for scrolling */
}

#horizontal_scroll {
  background: grey;
  width: 50vw;
  height: 150vh;
  overflow-x: auto; /* Allow horizontal scroll */
  overflow-y: hidden; /* Hide vertical scroll */
  position: -webkit-sticky;
  position: sticky;
  top: 100vh; /* Stick to the bottom of the viewport */
  height: 50vh; /* Adjust height so it's visible */
}

#horizontal_scroll div {
  width: 100vw; 


<div id="horizontal_scroll">
  <div></div>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.