z-index不仅适用于fullPage.js

时间:2018-02-06 00:50:38

标签: jquery css z-index

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

此时,似乎z-index无法正常工作:在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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

通过添加位置:相对于z-index:2来固定节div,以及设置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;
}