Css视差不起作用

标签 css parallax

大家好,我正在学习 W3S 教程,我想存档视差效果。试了很多次,不知道为什么图片不显示。
我在另一个元素上做了完全相同的事情,而且效果很好。我真的不知道我做错了什么。由于我的“愚蠢问题”,我的声誉在这里有点不好,所以如果这个问题冒犯了某人,我很抱歉。
看看我的代码:

* {
  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%。

关于Css视差不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48962996/

相关文章:

javascript - 具有视差的网页部分在滚动时滞后

html - CSS3 视差滚动

html - 如何让 Jarallax MDB 工作?

css - 是否可以使用单个 @keyframes 规则在两个方向上播放动画?

css - img src SVG 使用 CSS 改变样式

html - 列表项中的 Bootstrap 侧边栏链接占据了整个按钮

javascript - JQuery 视差背景随鼠标悬停移动

javascript - jQuery的scrollTop不会变成负数

css - 如何在CSS中导入字体?

html - 在单个 div 下添加 2 个图像