我的导航栏中间有一个图像阻止了我的链接,我在下面做了一些代码来表明这一点。我尝试用z-index修复此问题,但它一直阻止我的链接
由于我的其余代码(不在此代码段中),我无法将图像放在导航栏中。我认为如果我得到<a>
背后的绝对图像应该可以解决,但我无法用z-index&#39;
$(document).ready(function () {
$("nav a").click(function(event){
$("article").removeClass("slide_1");
$("article").removeClass("slide_2");
$("article").removeClass("slide_3");
var clickedId = event.target.id;
$('article').addClass("slide_"+clickedId);
});
});
&#13;
header {
width: 100%;
height: 100px;
position: relative;
background: #ffe7d9;
}
nav{
width: 100%;
text-align: center;
position: absolute;
bottom: 0;
border: 1px solid black;
background-color: #fed5b7;
}
nav ul{
display: inline-block;
margin: 0;
width: 100%;
padding: 0;
}
nav li{
width: 30%;
text-align: center;
box-sizing: border-box;
display: inline-block;
list-style-type: none;
color: black;
font-size: 1.1em;
line-height: 35px;
}
nav li a{
width: 100%;
height: 100%;
display: block;
color: black;
cursor: pointer;
}
nav li a.no-background{
background-image: none !important;
}
img.headerlogo{
position: absolute;
width: 15%;
height: 200%;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
bottom: 0;
}
article{
width: 100%;
height: 200px;
}
.slide_1{
background-color: red;
}
.slide_2{
background-color: green;
}
.slide_3{
background-color: blue;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<nav id="menu">
<img src="http://lorempixel.com/160/90" class="headerlogo">
<ul>
<li><a id="1">Link1</a></li>
<li class="logo"><a id="2">Link2</a></li>
<li><a id="3">Link3</a></li>
</ul>
</nav>
</header>
<article>
</article>
&#13;
答案 0 :(得分:2)
使用此
nav{
z-index:9;}
img.headerlogo{
z-index:-1;
opacity:0.5;
}
$(document).ready(function () {
$("nav a").click(function(event){
$("article").removeClass("slide_1");
$("article").removeClass("slide_2");
$("article").removeClass("slide_3");
var clickedId = event.target.id;
$('article').addClass("slide_"+clickedId);
});
});
header {
width: 100%;
height: 100px;
position: relative;
background: #ffe7d9;
}
nav{
width: 100%;
text-align: center;
position: absolute;
bottom: 0;
border: 1px solid black;
background-color: #fed5b7;
z-index:9;
}
nav ul{
display: inline-block;
margin: 0;
width: 100%;
padding: 0;
}
nav li{
width: 30%;
text-align: center;
box-sizing: border-box;
display: inline-block;
list-style-type: none;
color: black;
font-size: 1.1em;
line-height: 35px;
}
nav li a{
width: 100%;
height: 100%;
display: block;
color: black;
cursor: pointer;
}
nav li a.no-background{
background-image: none !important;
}
img.headerlogo{
position: absolute;
width: 15%;
height: 200%;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
bottom: 0;
z-index:-1;
opacity:0.5;
}
article{
width: 100%;
height: 200px;
}
.slide_1{
background-color: red;
}
.slide_2{
background-color: green;
}
.slide_3{
background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<nav id="menu">
<ul>
<img src="http://lorempixel.com/160/90" class="headerlogo">
<li><a id="1">Link1</a></li>
<li class="logo"><a id="2">Link2</a></li>
<li><a id="3">Link3</a></li>
</ul>
</nav>
</header>
<article>
</article>
答案 1 :(得分:0)
将img tage置于外部并更改类headerlogo
$(document).ready(function () {
$("nav a").click(function(event){
$("article").removeClass("slide_1");
$("article").removeClass("slide_2");
$("article").removeClass("slide_3");
var clickedId = event.target.id;
$('article').addClass("slide_"+clickedId);
});
});
&#13;
header {
width: 100%;
height: 100px;
position: relative;
background: #ffe7d9;
}
nav{
width: 100%;
text-align: center;
position: absolute;
bottom: 0;
border: 1px solid black;
background-color: #fed5b7;
}
nav ul{
display: inline-block;
margin: 0;
width: 100%;
padding: 0;
}
nav li{
width: 30%;
text-align: center;
box-sizing: border-box;
display: inline-block;
list-style-type: none;
color: black;
font-size: 1.1em;
line-height: 35px;
}
nav li a{
width: 100%;
height: 100%;
display: block;
color: black;
cursor: pointer;
}
nav li a.no-background{
background-image: none !important;
}
img.headerlogo{
position: relative;
width: 15%;
height: 100%;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
bottom: 0;
}
article{
width: 100%;
height: 200px;
}
.slide_1{
background-color: red;
}
.slide_2{
background-color: green;
}
.slide_3{
background-color: blue;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<nav id="menu">
<ul>
<li><a id="1">Link1</a></li>
<li class="logo"><a id="2">Link2</a></li>
<li><a id="3">Link3</a></li>
</ul>
</nav>
</header>
<img src="http://lorempixel.com/160/90" class="headerlogo">
<article>
</article>
&#13;
答案 2 :(得分:0)
将z-index:-1
提交至z-index: 1;
,将z-index:1; position:relative;
提交至nav
。
$(document).ready(function () {
$("nav a").click(function(event){
$("article").removeClass("slide_1");
$("article").removeClass("slide_2");
$("article").removeClass("slide_3");
var clickedId = event.target.id;
$('article').addClass("slide_"+clickedId);
});
});
&#13;
header {
width: 100%;
height: 100px;
position: relative;
background: #ffe7d9;
}
nav{
width: 100%;
text-align: center;
position: absolute;
bottom: 0;
border: 1px solid black;
background-color: #fed5b7;
z-index: 1;
}
nav ul{
display: inline-block;
margin: 0;
width: 100%;
padding: 0;
position: relative;
}
nav li{
width: 30%;
text-align: center;
box-sizing: border-box;
display: inline-block;
list-style-type: none;
color: black;
font-size: 1.1em;
line-height: 35px;
}
nav li a{
width: 100%;
height: 100%;
display: block;
color: black;
cursor: pointer;
}
nav li a.no-background{
background-image: none !important;
}
img.headerlogo{
position: absolute;
width: 15%;
height: 200%;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
bottom: 0;
z-index: -1;
}
article{
width: 100%;
height: 200px;
}
.slide_1{
background-color: red;
}
.slide_2{
background-color: green;
}
.slide_3{
background-color: blue;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<nav id="menu">
<img src="http://lorempixel.com/160/90" class="headerlogo">
<ul>
<li><a id="1">Link1</a></li>
<li class="logo"><a id="2">Link2</a></li>
<li><a id="3">Link3</a></li>
</ul>
</nav>
</header>
<article>
</article>
&#13;