简体   繁体   English

如何在英雄图像上覆盖透明导航栏,并在英雄图像上有功能正常的按钮?

[英]How do I overlay a transparent navbar over a hero image and have a functioning button on the hero image?

I've set my nav bar as transparent on top of my hero image, however, the buttons on my hero image do not work. 我已将导航栏设置为在英雄图像上方透明,但是,英雄图像上的按钮不起作用。

The nav-bar has a z-index of 1, and my hero image, text and button has a z-index of -1. 导航栏的z索引为1,我的英雄图像,文本和按钮的z索引为-1。 This makes the button unclickable, as it is set to be behind the navbar. 这将使按钮不可单击,因为它被设置在导航栏的后面。

Things I've tried: 我尝试过的事情:

-I've tried to give my button a z-index of 1, but it doesn't work -我尝试将按钮的z-index设置为1,但是它不起作用

-I've tried to wrap my button in a div class and set the z-index of that to 1, but it doesn't work -我尝试将我的按钮包装在div类中,并将其z-index设置为1,但这不起作用

-If I reverse the z-index of the nav bar and hero image, the buttons work, however, the nav bar is set behind the image and cannot be seen. -如果反转导航栏和英雄图像的z索引,则按钮起作用,但是导航栏设置在图像后面,无法看到。

How do I accomplish having the nav bar on top of the hero image AND have my button clickable? 如何完成将导航栏放在英雄图像上方并使我的按钮可单击?

 .top-nav{ font-size: 20px; margin-top:0em; margin-bottom:0em; font-weight:600; padding: 0px 32px; color: white !important; background: transparent; } .navbar-overlay { position:relative; margin-bottom: -104px; z-index: 1; } .first-section-hero { position: relative; min-height: auto; height:900px; margin-top: 0em; padding-bottom: 10em; background-image:url("{% static 'img/yellow_swoosh.svg' %}"); background-position: center center; -webkit-background-size: cover; -moz-background-size: cover; background-size: cover; -o-background-size: cover; background-repeat:no-repeat; z-index: -1; } 
 <section class="top-nav "> <div class= navbar-overlay > <nav class="navbar navbar-expand-lg navbar-dark "> <a class="navbar-brand" href="{{ home_url }}">Name</a> <div class="collapse navbar-collapse " id="navbarText"> <ul class="navbar-nav mx-auto"> <li class="nav-item "> <a class="nav-link" href="/articles">Resources</a> </li> <li class="nav-item"> <a class="nav-link" href="/features">Features</a> </li> <li class="nav-item"> <a class="nav-link" href="/about">About </a> </li> </ul> </div> </nav> </div> </section> <section class="first-section-hero" > <div class="container"> <div class="row"> <div class="col-lg-12 col-xs-12 "> <h1>TITLE</h1> <a href="#" class="btn btn-default btn-xl">FIND OUT MORE</a> </div> </div> </div> </section> 

您的Z索引应大于与按钮重叠的导航栏。

Just set z-index like 只需将z-index设置为

.image {
  z-index : 1000;
}
.navbar {
  z-index : 1001;
}

.buttons {
  z-index : 1002;
}

and your problem will solve 你的问题会解决

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

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