html - 设置可滚动的背景图片
问题描述
我目前有这个小提琴:
https
:
//jsfiddle.net/0g3u8452/1/ 我有一个 1920x4000 的图像,我希望它像
background-size: cover
但由于图像的高度很重要,我希望能够向下滚动以继续看到它
我拍了一张我想要得到的结果的照片:
预先感谢您的任何帮助 :)
解决方案
尝试使用<img>
withposition: absolute
作为背景?
.container {
position: relative;
}
.container img.background-img {
position: absolute;
width: 100%;
top: 0;
left: 0;
z-index: -1;
}
body {
padding: 0;
margin: 0;
}
<div class="container">
<img src="http://via.placeholder.com/1920x4000" class="background-img">
<div class="other">Other elements</div>
</div>
推荐阅读
- reactjs - 使用 React-Router 显示细节组件
- database - 对可空结构字段使用 nil 或 Null* 更好
- java - jar libs\commons-compress-1.18.jar 有一个主类 org.apache.commons.compress.archivers.Lister 与声明的 main 不匹配
- cmake - CPACK .deb 安装程序备份以前安装的版本
- php - 在字符串中创建变量
- vb.net - 无法取消申请
- css - 为什么 .class element {} 不覆盖 element {}?
- excel - 引用包含换行符和尾随空格的表列名称
- if-statement - 如何修复 if/else 语句
- python - 如何在 Python 的 unittest 框架中模拟返回 self 的方法