html - 我正在制作“视差”效果,但它不起作用
问题描述
我有点新,HTML
并且CSS
正在建立一个网站,但我似乎无法在我的图像上创建视差效果......图像只是没有显示。你能看出我的(简化的)代码有什么问题吗?
.parallax {
background-image: url("images/start-background.jpg");
height: 100%;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
<!DOCTYPE html>
<html>
<head>
<link href="./style.css" type="text/css" rel="stylesheet">
</head>
<body>
<div class="parallax"></div>
<h1 class="title-home">This is my title</h1>
<h2 class="subtitle-home">This is my subtitle. Example, example, etc.</h2>
<div class="parallax"></div>
</body>
</html>
解决方案
你应该设置一个min-height
.I made 500px here 但你可以更改。
.parallax {
/* The image used */
background-image: url("https://www.metoffice.gov.uk/binaries/content/gallery/metofficegovuk/hero-images/weather/cloud/cumulus-cloud.jpg");
min-height: 500px;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
<!DOCTYPE html>
<html>
<head>
<link href="./style.css" type="text/css" rel="stylesheet">
</head>
<body>
<div class="parallax"></div>
<h1 class="title-home">This is my title</h1>
<h2 class="subtitle-home">This is my subtitle. Example, example, etc.</h2>
<div class="parallax"></div>
</body>
</html>
推荐阅读
- vba - 尝试使用 CopyValues 时出现错误“编译错误:未定义子或函数”
- android - 在我的 android 项目上设置 OpenCV 后,在执行 com.android.build.gradle.internal.tasks.Workers$ActionFacade 时发生构建失败
- python - tkinter 按钮回调中的 Lambda 函数
- jenkins - 在 jenkins 文件中将节点包装在函数中是个好主意吗?
- python - Python 脚本和等效命令的运行方式不同
- excel - MINIFS、MAXIFS 等公式标准中的转义运算符 <,>,=
- c++ - Cryptopp 制作 ARM 32 位共享库
- python - TypeError:“模块”对象不可调用。我尝试了各种解决方案,但到目前为止没有任何效果
- firebase - 无法从方法“_userFromFirebaseUser”返回“Null”类型的值,因为它的返回类型为“User”
- python-3.x - 如何优化这个 python 脚本 Pandas 的时间?