简体   繁体   English

CSS视差不起作用

[英]Css parallax doesn't work

Hey guys I'm following the W3S tutorials and I want to archive the parallax effect. 大家好,我正在关注W3S教程,我想存档视差效果。 I've tried many times and I don't know why the picture doesn't show. 我已经尝试了很多次,但我不知道为什么图片不显示。
I did the exact same thing on another project and it worked just fine. 我在另一个项目上做了完全相同的事情,并且效果很好。 I really don't know what I did wrong. 我真的不知道我做错了什么。 My reputation it's kinda bad here because of my "stupid questions", so I'm sorry if this question offend someone. 我的声誉在这里有点不好,因为我的“愚蠢问题”,如果这个问题冒犯了我,我感到抱歉。
Have a look at my code: 看一下我的代码:

 * { margin: 0; padding: 0; } body { margin: 0; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 19px; line-height: 1.6; } #showcase { background-image: url('https://picsum.photos/g/1900/1080?random'); height: 100vh; background-position: center; background-size: cover; display: flex; flex-direction: column; justify-content: center; align-items: center; position: top; } .button { background-color: black; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; border-radius: 8px; } .Bshadow:hover { box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19); } .pacifont { font-family: 'Pacifico', cursive; font-size: 4.8rem; color: white; } .name { color: #008c06; } .topnav { overflow: hidden; /* background-color: #333; */ border-bottom: 3px solid #008c06; } .sticky { position: fixed; top: 0; width: 100% } .topnav a { float: left; display: block; color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; } .topnav a:hover { background-color: #ddd; color: black; } .active { background-color: #008c06; color: white; } .topnav .icon { display: none; } @media screen and (max-width: 600px) { .topnav a:not(:first-child) { display: none; } .topnav a.icon { float: right; display: block; } } @media screen and (max-width: 600px) { .topnav.responsive { position: relative; } .topnav.responsive .icon { position: absolute; right: 0; top: 0; } .topnav.responsive a { float: none; display: block; text-align: left; } } .parallax { /* The image used */ background-image: url("https://picsum.photos/500/1081/?random'"); /* Full height */ height: 100%; width: 100%; /* Create the parallax scrolling effect */ background-attachment: fixed; background-position: center; background-repeat: no-repeat; background-size: cover; } 
 <header id="showcase"> <div class="topnav sticky" id="myTopnav"> <a href="#home" class="active">Home</a> <a href="#news">News</a> <a href="#contact">Contact</a> <a href="#about">About</a> <a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">&#9776;</a> </div> <h1 class="pacifont">Welcome <a class="name">Felix!</a></h1> <a href="#" class="button Bshadow">READY?</a> </header> <a class="weatherwidget-io" href="https://forecast7.com/en/50d854d35/brussels/" data-label_1="Bruxelles" data-font="Jura" data-icons="Climacons Animated" data-days="3" data-theme="gray">Bruxelles</a> <h1>wtf</h1> <div class="parallax"></div> <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Delectus odit dolorum sed ut, doloremque consectetur.</p> 

将.parallax类的高度更改为100vh,而不是100%。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM