javascript - CSS:如何使粘性元素不粘在页面顶部,而是粘在特定的像素或位置?
解决方案
如果我正确理解了您的问题,我认为您的目标可能是sticky
职位。 更多信息
我根据您的图像为您制作了这个示例。希望能帮助到你:
body {margin:0; padding:0; background-color:orange;}
.container {
position:relative;
margin:0 auto;
width:400px;
margin-top:20px;
margin-bottom:40px;
}
img {
width:100%;
display:block;
margin-top:-40px;
}
.number {
position:sticky;
top:30px;
margin-left:-40px;
font-size:40px;
color:#fff;
text-shadow: 2px 2px 3px rgba(0,0,0,0.8);
font-weight:bold;
}
<div class="container">
<div class="number">
+01
</div>
<img src="https://image.shutterstock.com/image-vector/greece-parthenon-sketch-600w-78255484.jpg" alt="">
</div>
<div class="container">
<div class="number">
+02
</div>
<img src="https://image.shutterstock.com/image-vector/greece-parthenon-sketch-600w-78255484.jpg" alt="">
</div>
<div class="container">
<div class="number">
+03
</div>
<img src="https://image.shutterstock.com/image-vector/greece-parthenon-sketch-600w-78255484.jpg" alt="">
</div>
<div class="container">
<div class="number">
+04
</div>
<img src="https://image.shutterstock.com/image-vector/greece-parthenon-sketch-600w-78255484.jpg" alt="">
</div>
推荐阅读
- android - 以编程方式列出 Gradle Android 项目的所有运行时依赖项
- node.js - 如何在 next.js 的 getStaticPaths 中使用动态路由实现分页?
- javascript - 显示 Element 的通用变量在尝试按索引访问时隐式出现“任何”类型错误
- html - rect 的笔画不遵循 rect 的半径
- javascript - 发现少数设备后 BLE 扫描停止
- python - Django 自定义 URL 映射:模板中的日期模式不匹配
- api - 做 Github card move http get 请求时“位置”是什么意思?
- jira-xray - Cucumber 测试执行的测试环境
- android - React 本机相机无法渲染
- oracle - 在不等待结果的情况下运行 oracle sql 命令