html - 重叠粘性元素但内容保持默认滚动
问题描述
我在表述我的问题时有些挣扎,并且还没有在网上找到解决方案。
我的问题:我正在创建应该堆叠在一起的全视口幻灯片(具有透明度)。有很多解决方案。但我希望幻灯片的内容正常滚动,就像您滚动普通网站时所期望的那样(即文本不会卡在屏幕顶部,但背景会卡住)。
这是我玩了几个星期的纯 html 示例。我不知道这是否是最有希望的解决方案,但我认为它解释了我想要实现的目标。注意:行为已经有些正确,但是幻灯片之间有很多不必要的间距(=目标是“连接”右侧的灰色背景而没有间距)。我认为对此有更好的解决方案。
更新了此代码段以匹配评论中的提议。我们显然走得更近了,但是正如您在更新的代码段中看到的那样,有很多不必要的间距。
body {
margin: 0;
padding: 0;
color: #000;
}
h1, h2, p {
text-align: center;
width: 100%;
position:relative;
}
h1 {
margin-top: 40vh;
min-height: 20vh;
font-size: 48pt;
}
.background.a {
background-image: linear-gradient(to right, #f00a, #fff0 10%);
}
.background.b {
background-image: linear-gradient(to right, #fff3 20%, #0f0a 30%, #fffa 40%);
}
.background.c {
background-image: linear-gradient(to right, #fff3 50%, #00fa 60%, #fffa 70%);
}
.background {
position: sticky;
height: 100vh;
top: 0;
}
.content {
min-height: 100vh;
position: relative;
top: -100vh;
}
<div class="background a"></div>
<div class="content">
<h1>Some content</h1>
<h2>creates slides with images ...</h2>
</div>
<div class="background b"></div>
<div class="content">
<h1>More content</h1>
<h2>creates slides with images ...</h2>
</div>
<div class="background c"></div>
<div class="content">
<h1>Some more content</h1>
<h2>creates slides with images ...</h2>
</div>
我希望你能得到我想要达到的目标。我总是想知道这些不精确的 Stack Overflow 问题,现在我自己写一个并没有做得更好……非常感谢。如果我应该澄清一些事情,请告诉我。
解决方案
推荐阅读
- python - Python 中的 now = datetime.datetime.now() 和 now = datetime.now() 有什么区别?
- navigation - 机器人在达到目标之前没有移动
- c - 在 LLVM 通道中识别匿名结构及其元素
- c# - 在我的 flowlayoutpanel 中打印用户控件的集合
- javascript - 如何使用 API 在 Vuejs 中使用复选框过滤数据?
- javascript - Next.js 中是否可以有一个仅限移动设备的页面?
- javascript - 如何计算 N 个数组中每个元素的总和,并将其存储在另一个数组中?
- c - 尝试在 qsort 函数中打印字符串
- java - 方法调用不起作用(可能很简单,我只是不明白)
- linux - Linux 模块加载