简体   繁体   English

使用 z-index 将位置固定元素移动到某物后面

[英]Move position fixed element behind something by using z-index

I have an arrow on one of my websites indicating to users that they can keep scrolling down on the page.我的一个网站上有一个箭头,向用户表明他们可以在页面上继续向下滚动。 I set the position of this arrow to fixed so users keep seeing it as they scroll.我将此箭头的位置设置为固定,以便用户在滚动时继续看到它。 However, I want it to not be seen when you are at the footer.但是,我希望当您在页脚时不会看到它。 I've tried changing the z-index of the footer so that it would be positioned above the fixed position arrow, but that didn't work.我尝试更改页脚的 z-index,使其位于固定位置箭头上方,但这不起作用。 How do I make it so that the footer will be seen above the arrow?我该如何制作才能在箭头上方看到页脚?

Here is an example of what is going on.. http://codepen.io/aahmed2/pen/dpjozP?editors=1100这是正在发生的事情的一个例子.. http://codepen.io/aahmed2/pen/dpjozP?editors=1100

 #picture { background: url(http://blog.oxforddictionaries.com/wp-content/uploads/mountain-names.jpg) fixed bottom; background-size: cover; height: 900px; } #picture h1 { color: #fff; text-align: center; font-size: 130px; padding-top: 40px; } #down-arrow { position: fixed; z-index: 1; font-size: 25px; color: #ffffff; bottom: 10%; left: 1%; } .bounce { -webkit-animation: bounce 4s infinite; animation: bounce 4s infinite; } /* .bounce animation */ @-webkit-keyframes bounce { 0%, 20%, 50%, 80%, 100% { -webkit-transform: translateY(0); transform: translateY(0); } 40% { -webkit-transform: translateY(-20px); transform: translateY(-20px); } 60% { -webkit-transform: translateY(-10px); transform: translateY(-10px); } } @-moz-keyframes bounce { 0%, 20%, 50%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-20px); } 60% { transform: translateY(-10px); } } @keyframes bounce { 0%, 20%, 50%, 80%, 100% { -ms-transform: translateY(0); transform: translateY(0); } 40% { -ms-transform: translateY(-20px); transform: translateY(-20px); } 60% { -ms-transform: translateY(-10px); transform: translateY(-10px); } } #main { padding-top: 80px; padding-bottom: 80px; } #footer { background-color: #333332; height: 300px; z-index: 2; text-align: center; padding: 20px; color: #ffffff; }
 <div id="picture"> <div class="container"> <h1>WELCOME<br>to the<br>ROCKIES</h1> </div> </div> <div id="down-arrow" class="bounce"><span class="glyphicon glyphicon-chevron-down"></span></div> <div id="main"> <div class="container"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam consectetur sodales arcu, hendrerit fermentum nisi sagittis et. Aenean vel ex at purus feugiat facilisis. Pellentesque egestas, velit hendrerit porta pretium, mi sapien laoreet arcu, eu pretium libero ligula fermentum mauris. Etiam ac finibus lorem. Mauris sollicitudin, libero sit amet pulvinar placerat, nibh urna pharetra felis, vel suscipit tellus lectus sit amet augue. Phasellus sed porta tortor. Duis bibendum quam pretium, vehicula erat vitae, ullamcorper mauris. Donec a lacinia est. Proin vel tellus erat. Aenean ultrices sollicitudin sem sit amet dignissim. Vivamus et semper eros, at porttitor erat. Ut consequat nulla ac hendrerit rhoncus. Donec feugiat lobortis tellus at ultricies.</p> </div> </div> <div id="footer"> <h2>FOOTER</h2> </div>

add position: relative;添加position: relative; to the footer:到页脚:

#footer {
   background-color: #333332;
   height: 300px;
   z-index: 2;
   text-align: center;
   padding: 20px;
   color: #ffffff;
   position: relative;
}

Just give position to your footer.只要给你的页脚位置

  footer {
    position: relative;
    z-index: 5;
  }

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

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