gpt4 book ai didi

html - 如何分别滚动多个水平滚动容器?

转载 作者:行者123 更新时间:2023-11-28 00:39:29 25 4
gpt4 key购买 nike

我是编码的新手,但我又一次偶然发现了另一个我自己似乎无法解决的问题。

对于类似旅游博客的网站,我希望有一个显示图 block 的垂直滚动菜单。瓷砖始终具有相同的大小和宽度。每个“行”代表一天,应该在侧面包含多个图 block ,使每一行成为垂直滚动容器内的水平滚动容器(您可以垂直滚动日期,水平滚动每一天的条目)。

为了测试,我想出了一个简单的代码,令我惊讶的是,就“它能工作”而言,它已经相当不错了。但是有一个问题:水平滚动时,所有容器都向左/向右滚动。

如何实现一次只有一个容器水平滚动,我错过了什么?

提前致谢! :)

(PS:是的,这些图 block 是为了无缝接触,是的,我只是为 Chrome atm 禁用了滚动条 ^^)

* {
padding: 0;
margin: 0;
}

#vertical_scroll_container {
width: 60vw;
height: 100vh;
overflow: scroll;
white-space: nowrap;
margin: 0 auto;
}

#vertical_scroll_container::-webkit-scrollbar {
display: none;
}

.horizontal_scroll_container {
width: 100%;
height: 240px;
overflow-y:scroll;
white-space: nowrap;
}

.horizontal_scroll_container::-webkit-scrollbar {
display: none;
}

.scroll_item {
position: relative;
display: inline-block;
height: 240px;
width: 50vw;
background-color: bisque;
}

.caption {
font-size: 26px;
font-family: sans-serif;
position: absolute;
left: 10px;
bottom: 10px;
}
<!DOCTYPE>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
<div id="vertical_scroll_container">
<div class="horizontail_scroll_container">
<div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div><!--
--><div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div><!--
--><div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div><!--
--></div>
<div class="horizontail_scroll_container">
<div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div><!--
--><div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div>
</div>
<div class="horizontail_scroll_container">
<div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div>
</div>
<div class="horizontail_scroll_container">
<div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div><!--
--><div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div><!--
--><div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div><!--
--></div>
<div class="horizontail_scroll_container">
<div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div><!--
--><div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div>
</div>
<div class="horizontail_scroll_container">
<div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div>
</div>
<div class="horizontail_scroll_container">
<div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div><!--
--><div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div><!--
--><div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div><!--
--></div>
<div class="horizontail_scroll_container">
<div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div><!--
--><div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div>
</div>
<div class="horizontail_scroll_container">
<div class="scroll_item">
<p class="caption">Titel in<br>bis zu<br>drei Zeilen</p>
</div>
</div>
</div>
</body>
</html>

最佳答案

您在 html 中有错字(水平而不是水平),并尝试更改为:

#vertical_scroll_container {
width: 60vw;
height: 100vh;
overflow-x: hidden; <-- you don't want scroll sideways here.
white-space: nowrap;
margin: 0 auto;
}

而 x 是水平的,所以:

.horizontal_scroll_container {
width: 100%;
height: 240px;
overflow-x: scroll; <-- or auto, to have the content scrollable
white-space: nowrap;
}

关于html - 如何分别滚动多个水平滚动容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54368225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com