jquery - z-index 不适用于 fullPage.js

标签 jquery css z-index

我有以下一页设置,其中包含一个容器和 3 个 div。我为视差效果的 3 个 div 中的每一个设置了一个 :before div,并相应地设置了 z-index,以便带有文本的 div 与带有背景图像的 :before div 重叠。一切正常,直到我插入 jquery 插件 fullPage.js。

此时,z-index 似乎无法正常工作,因为 :before div 将 div 与文本重叠。

我怀疑可能与下面找到的 jquery.fullPage.css 有冲突。 有什么想法吗?

https://github.com/alvarotrigo/fullPage.js/blob/master/jquery.fullPage.css

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

enter code here html,
body {
  height: 100%;
}

body {
  font-family: 'Indie Flower', sans-serif;
}

a {
  text-decoration: none;
  color: #f2b632;
}

.container {
  height: 100%;
  display: grid;
  grid-template-rows: repeat(3, 100vh);
}

.bio {
  background-color: #252839;
  font-size: 1em;
  color: #f2b632;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  padding: 0 30px;
}

bio>h1 {
  z-index: 2;
}

.bio:before {
  content: ' ';
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  opacity: 0.1;
  background-image: url(../images/logo1.svg);
  background-repeat: no-repeat;
  background-position: center;
  background-attachment: fixed;
}

.photos {
  background-color: #677077;
  font-size: 1em;
  color: white;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  padding: 0 30px;
}

.photos>h1 {
  z-index: 2;
}

.photos:before {
  content: ' ';
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  opacity: 0.1;
  background-image: url(../images/logo1.svg);
  background-repeat: no-repeat;
  background-position: center;
  background-attachment: fixed;
}

.contact {
  background-color: #f2b632;
  font-size: 1em;
  color: #252839;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  padding: 0 30px;
}

.contact>h1 {
  z-index: 2;
}

.contact:before {
  content: ' ';
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  opacity: 0.1;
  background-image: url(../images/logo1.svg);
  background-repeat: no-repeat;
  background-position: center;
  background-attachment: fixed;
}

@media only screen and (min-width: 480px) and (max-width: 768px) {
  .bio,
  .photos,
  .contact {
    font-size: 1.6em;
  }
}

@media only screen and (min-width: 769px) {
  .bio,
  .photos,
  .contact {
    font-size: 2.7em;
  }
}
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Parallax Effect</title>
  <link rel="stylesheet" type="text/css" href="css/jquery.fullPage.css" />
  <link rel="stylesheet" type="text/css" href="css/parallax-js.css">
  <link href="https://fonts.googleapis.com/css?family=Indie+Flower" rel="stylesheet">
  <script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js">
  </script>
</head>

<body>

  <div id="fullpage" class="container">
    <div class="section bio ">
      <h1>My name is Leo. I am a beginner freelance web developer based in Toronto, Canada.</h1>
    </div>
    <div class="section photos">
      <h1>Let me build you a website.</h1>
    </div>
    <div class="section contact">
      <h1>Contact me</h1>
      <div>
        <i class="fab fa-linkedin fa-5x"></i>
        <i class="fas fa-at fa-5x"></i>
      </div>
    </div>
  </div>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
  </script>
  <script type="text/javascript" src="scripts/jquery.fullPage.js"></script>
  <script>
    $(document).ready(function() {
      $('#fullpage').fullpage({
        scrollBar: true
      });
    });
  </script>

</body>

</html>

最佳答案

通过将 position: relative 和 z-index: 2 添加到 divs 部分,并将 z-index: -1 设置为 div::before 来修复。

.bio {
background-color: #252839;
font-size: 1em;
color: #f2b632;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
position: relative;
z-index: 2;
padding: 0 30px;
}

.bio:before {
content: ' ';
display: block;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: -1;
opacity: 0.1;
background-image: url(../images/logo1.svg);
background-repeat: no-repeat;
background-position: center;
background-attachment: fixed;
}

关于jquery - z-index 不适用于 fullPage.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48633841/

相关文章:

html - 如何使用 CSS 更改滚动条位置?

javascript - 在 HTML DOM 树中查找元素 A 是否在元素 B 之后

css - 父元素嵌入阴影后面的子元素边框

jquery - DotNetNuke 如何将 javascript 或 css 文件添加到内容资源管理中?

jquery - 调整大小时保持相同高度 (jQuery)

javascript - 在模态中填充内容,当单击 <a> 标签时,不会触发单击事件

javascript - 如何为某些元素禁用 e.preventDefault

CSS 主体渐变

css - 谷歌翻译正在移除 CSS

css - :hover is making the next link inline disappear and double images it over the link the mouse is on