html - 与导航栏无关的一切,重叠并打断它

标签 html css

我想在我的页面顶部创建一个导航栏,无论您以何种方式滚动,它都会跟随。 我创建了它,然后在其下创建了一个幻灯片。问题是,与我的幻灯片相关的所有内容都会中断导航栏,当它滚动浏览时,它们会重叠。我不知道如何解决这个问题,希望得到一些帮助:)

CSS


/* HEADER - HEADER - HEADER */ 

/* Style the header */
.header {
  background-color: lightgray;
  padding: 20px;
  text-align: center;
}

/* Style the top navigation bar */
.menu_navigation {
  position: fixed;
  overflow: hidden;
  background-color: #333;
  top: 0; 
  width: 100%;
}

/* Style the topnav links */
.menu_navigation a {
  float: left;
  display: block;
  color: #f2f2f2;
  text-align: center;
  padding: 15px 25px;
  text-decoration: none;
}

/* Change color on hover */
.menu_navigation a:hover {
  background-color: rgb(0, 162, 255);
  color: black;
}

/* Create three equal columns that floats next to each other */
.column {
  float: left;
  width: 33.33%;
  padding: 10px;
}

/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}

/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
@media screen and (max-width:600px) {}
.column {
    width: 100%;
  }  


  * {box-sizing: border-box}
  body {font-family: Verdana, sans-serif; margin:0}
  .mySlides {display: none}
  img {
    vertical-align: auto;
    position: relative;
    top: 52px;
  }
  #billede1, #billede2, #billede3 {
    filter: blur(8px);
  }




  /* Slideshow container */
  .slideshow-container {
    width: 1500;
  }
  /* Next & previous buttons */
  .prev, .next {
    position: absolute;
    top: 50%;
    width: auto;
    padding: 16px;
    margin-top: -22px;
    color: white;
    transition: 0.6s ease;
  }

  /* Position the "next button" to the right */
  .next {
    right: 0;
    border-radius: 3px 0 0 3px;
  }

  /* On hover, add a black background color with a little bit see-through */
  .prev:hover, .next:hover {
    background-color: rgba(0,0,0,0.8);
  }

  /* Caption text */
  .text {
    color: #000000;
    font-size: 30px;
    padding: 8px 12px;
    position: absolute;
    bottom: -1200px;
    width: 100%;
    text-align: center;
  }

  /* Number text (1/3 etc) */
  .numbertext {
    color: #f2f2f2;
    font-size: 12px;
    padding: 8px 12px;
    position: absolute;
    top: 0;
  }

  /* The dots/bullets/indicators */
  .dot {
    cursor: pointer;
    height: 15px;
    width: 15px;
    margin: 0 2px;
    background-color: #bbb;
    border-radius: 50%;
    display: inline-block;
    transition: background-color 0.6s ease;
  }

  .active, .dot:hover {
    background-color: #717171;
  }

  /* Fading animation */
  .fade {
    -webkit-animation-name: fade;
    -webkit-animation-duration: 1.5s;
    animation-name: fade;
    animation-duration: 1.5s;
  }

  @-webkit-keyframes fade {
    from {opacity: .4} 
    to {opacity: 1}
  }

  @keyframes fade {
    from {opacity: .4} 
    to {opacity: 1}
  }

  /* On smaller screens, decrease text size */
  @media only screen and (max-width: 300px) {
    .prev, .next,.text {font-size: 11px}
  }




.footer {
  background-color:blue;
  text-align: center;
  padding: 10px;
}

html

<!DOCTYPE html>
<html>
<title>W3.CSS</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<body>
    <div class="menu_navigation">
        <a href="#">Men</a>
        <a href="#">Women</a>
        <a href="#">Children</a>
        <a href="#">About Us</a>
        <a href="#">News</a>
    </div>  
    <!-- Slideshow, for under navigationsbaren-->    
    <div class="slideshow-container">

    <div class="mySlides fade">
      <div class="numbertext">1 / 3</div>
      <img src="C:\Users\Wahab\Desktop\hjemmesidenprojekt\billeder\1.jpg" id="billede1" style="width:100%" height="1000px">
      <div class="text">Skjorte - 150 kr</div>
    </div>

    <div class="mySlides fade">
      <div class="numbertext">2 / 3</div>
      <img src="C:\Users\Wahab\Desktop\hjemmesidenprojekt\billeder\2.jpg" id="billede2" style="width:100%" height="1000px">
      <div class="text">Mørke blå Chino bukser - 540 kr</div>
    </div>

    <div class="mySlides fade">
      <div class="numbertext">3 / 3</div>
      <img src="C:\Users\Wahab\Desktop\hjemmesidenprojekt\billeder\3.jpg" id="billede3" style="width:100%" height="1000px">
      <div class="text">Hvide Chinos - 430 kr</div>
    </div>
    <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
    <a class="next" onclick="plusSlides(1)">&#10095;</a>

    </div>
    <br>

    <div style="text-align:center">
      <span class="dot" onclick="currentSlide(1)"></span> 
      <span class="dot" onclick="currentSlide(2)"></span> 
      <span class="dot" onclick="currentSlide(3)"></span> 
    </div>


    <script>
    var slideIndex = 1;
    showSlides(slideIndex);
    function plusSlides(n) {
      showSlides(slideIndex += n);
    }
    function currentSlide(n) {
      showSlides(slideIndex = n);
    }
    function showSlides(n) {
      var i;
      var slides = document.getElementsByClassName("mySlides");
      var dots = document.getElementsByClassName("dot");
      if (n > slides.length) {slideIndex = 1}    
      if (n < 1) {slideIndex = slides.length}
      for (i = 0; i < slides.length; i++) {
          slides[i].style.display = "none";  
      }
      for (i = 0; i < dots.length; i++) {
          dots[i].className = dots[i].className.replace(" active", "");
      }
      slides[slideIndex-1].style.display = "block";  
      dots[slideIndex-1].className += " active";
    }
    </script>

</body>
</html>



最佳答案

您需要将导航栏的 z-index 设置为高于任何元素的任何其他 z-index。

z-index 提供了元素相互堆叠时的层次结构。

关于html - 与导航栏无关的一切,重叠并打断它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59221478/

相关文章:

Javascript HTML 选择下拉菜单

html - 更改 HTML 符号的字体颜色

javascript - 自动将文本插入表单?

javascript - 每次函数触发后清除 Jquery 动画距离?

css - 如何让我的 sass 登陆页面在 codepen 上运行?

javascript - 如何使导航栏可点击

jquery - 如何在 $(this) 中选择类

javascript - 如何为包含具有内联 block 显示的对象的 div 设置固定高度和自动宽度?

html - 围绕外部 div 容器中的内部 div 的边框

html - 使用 bootstrap 垂直居中 div