當您將鼠標懸停在區域<li>
上時,它將變爲紅色,但<a>
內部的區域保持白色。當我指向她時,區域<a>
變紅。這是分開發生的。錯誤行爲與:懸停
如何解決這個問題?如何使懸停區域<li>
整個領域都變成了紅色?
.menu {
z-index: 100;
width: 230px;
position: relative;
vertical-align: top;
display: inline-block;
background-color: #fff;
}
.menu * {
text-decoration: none;
font-size: 16px;
background-color: #fff;
}
.menu ul {
margin: 0;
padding-left: 10px;
list-style: none;
}
.menu ul li {
padding: 3px 0px 3px 10px;
color: #000;
display: block;
transition: all 0.5s ease 0.05s;
-webkit-transition: all 0.5s ease 0.05s;
}
.menu ul li a {
display: block;
color: #000;
}
.menu ul li:hover {
background: #e50003;
}
.menu ul li.active > a {
text-decoration: none;
}
.menu ul li a:hover {
text-decoration: none;
color: #fff;
background: #e50003;
}
.menu ul li .submenu {
display: none;
position: absolute;
width: 100%;
min-height: 100%;
top: 0;
left: 100%;
background: #ddd;
border-width: 0px 0px 0px 1px;
border-style: solid;
border-color: #bbb;
}
.menu ul li:hover > .submenu {
background-color: white;
display: block;
position: absolute;
left: 220px;
width: 250px;
top: 0;
z-index: 99;
transition: all 0.5s ease 0.05s;
-webkit-transition: all 0.5s ease 0.05s;
}
<div class="menu">
<ul>
<li class="active">
<a href="#">Пункт 1</a>
<div class="submenu submenu1">
<ul>
<li class="active">
<a href="#">Пункт 2</a>
</li>
</ul>
</div>
</li>
</ul>
</div>
'.menu *'將'a'設置爲白色背景。在您懸停之前,'li:hover'不會改變。考慮只需使用'.menu'。 –