为什么<a>在<li>应用悬停背景时,标签给出的输出与标签不同?



链接到我的jsfiddle作品

我将"导航栏"从基本的标题导航栏切换到自定义布局。我将 li 标签更改为 a 标签以包含类和单独的 css 设计。

在此更改之后,当我将鼠标悬停在它们上时,我的链接没有改变颜色。当我在标签中包含类时,是否有理由会发生这种情况。

.tl,
.tc,
.tr,
.bl,
.bc,
.br {
  text-decoration: none;
  color: green;
  font-size: 24px;
  font-family: Bungee Shade;
  cursor: pointer;
  border-radius: 10px;
  transition: .5s;
  position: fixed;
}
.tl {
  top: 45px;
  left: 60px;
}
.tc {
  margin-top: 45px;
  text-align: center;
  right: 50%;
}
.tr {
  margin-top: 45px;
  right: 60px;
}
.bl {
  bottom: 45px;
  margin-left: 60px;
}
.bc {
  bottom: 45px;
  text-align: center;
  right: 50%;
}
.br {
  bottom: 45px;
  right: 60px;
}
.tl:hover,
.tc:hover,
.tr:hover,
.bl:hover,
.bc:hover,
.br:hover {
  background-color: orange;
}
<div class="navbar">
  <a class="tl" href="#">HOME</a> 
  <a class="tc" href="#">MUSIC</a>
  <a class="tr" href="#">BIO</a>
  <a class="bl" href="#">TOUR</a>
  <a class="bc" href="#">SHOP</a>
  <a class="br" href="#">TSA</a>
</div>

请尝试在 a 标签类(而不是悬停状态(上添加一些填充或一些维度,看看它是否有效。 标签以内联方式工作,因此如果它们没有维度,则没有背景。

您必须将

position:relativez-index添加到navbar中,因为滑块当前与重叠。 所以hover不会发生在a标签上

* {
	padding: 0px;
	margin: 0px;
	box-sizing: border-box;
	
	/*background-image: url(test.JPG);*/ 
}
.navbar{
  position: relative;
  z-index: 2;
}
	
.tl, .tc, .tr, .bl, .bc, .br{
	text-decoration: none;
	color: green;
	font-size: 24px;
	font-family: Bungee Shade;
	cursor: pointer;
	border-radius: 10px;
	transition: .5s; 
	position: fixed;	
}
.tl{
	top: 45px;
	left: 60px;
}
.tc{
	margin-top: 45px;
	text-align: center;
	right: 50%;
}
.tr{
	margin-top: 45px;
	right: 60px;
}
.bl{
	bottom: 45px;
	margin-left: 60px;
}
.bc{
	bottom: 45px;
	text-align: center;
	right: 50%;
}
.br{
	bottom: 45px;
	right: 60px;
}
.tl:hover, .tc:hover, .tr:hover, .bl:hover, .bc:hover, .bl:hover{
	background-color: orange;
}

 #slider, .wrap, .slide-content{
	margin: 0;
	padding: 0;
	font-family: Bungee Shade ;
	width: 100%;
	height: 100vh;	
	overflow-x: hidden;	
	overflow-y: hidden;
}
.wrap{position:relative;}
.slide{
	background-size: cover;
	background-position: center;
	background-repeat: no-repeat;
}
.slide1{background-image: url('img/goho.jpg');
width: 330px;
height: 330px;
left: 33.3%;
margin-top: 12%;
position: fixed;
}
.slide2{background-image: url('');
}
.slide3{background-image: url('');}
.slide-content{
/*Text in the middle*/ 
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	text-align: center;
}
.slide-content span{
	font-size: 15px; /*rem*/
	color: black;
}
.arrow{
	cursor: pointer;
	position: absolute;
	top: 50%;
	margin-top: -30px;
	width: 0;
	height: 0;
	border-style: solid;
}
#arrow-left{
	border-width: 30px 40px 30px 0;
	border-color: transparent #000 transparent transparent;
	left: 0;
	margin-left: 30px;
}
#arrow-right{
	border-width: 30px 0 30px 40px;
	border-color: transparent transparent transparent #000;
	right: 0;
	margin-right: 30px;
}
<div class="navbar">
	<a class="tl" href="#">HOME</a>
	<a class="tc" href="music.htm">MUSIC</a>
	<a class="tr" href="#">BIO</a>
	<a class="bl" href="#">TOUR</a>
	<a class="bc" href="#">SHOP</a>
	<a class="br" href="#">TSA</a>
</div>
<div class ="wrap">
	<div id="arrow-left" onclick="slideLeft()" class="arrow"></div>
	<div id="slider">
	<div class="slide slide1">
			<div class="slide-content"></div>	
		</div>
	<div class="slide slide2">
			<div class="slide-content"></div>	
		</div>
		
	<div id="arrow-right" onclick="slideRight()" class="arrow"></div>
</div>