悬停时,我想严格定位菜单。菜单将更改颜色和大小,但不影响li
菜单。我该怎么办?
请注意,这假定是手风琴菜单。将鼠标悬停在菜单上时,导航(子)会展开。我已经花了很多时间,但是如果不弄乱潜水艇,就无法瞄准菜单。
<nav id="menu_box">
<ul class="menu">
<li> <a href="#">Menu</a>
<ul>
<li><a href="#">sub</a></li>
<li><a href="#">sub</a></li>
<li><a href="#">sub</a></li>
</ul>
</li>
<li> <a href="#">Menu</a>
<ul>
<li><a href="#">sub</a></li>
<li><a href="#">sub</a></li>
<li><a href="#">sub</a></li>
</ul>
</li>
<li> <a href="#">Menu</a>
<ul>
<li><a href="#">sub</a></li>
<li><a href="#">sub</a></li>
</ul>
</li>
</ul>
</nav>
这是CSS:
https://jsfiddle.net/kgrxqL0k/1/
最佳答案
也许这样:
.menu > li li a:hover {
color: pink;
}
#cssmenu,
#cssmenu ul,
#cssmenu ul li,
#cssmenu ul li a {
margin: 0;
padding: 0;
border: 0;
list-style: none;
line-height: 1;
display: block;
position: relative;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#cssmenu {
width: 220px;
font-family: Raleway, sans-serif;
color: #ffffff;
}
#cssmenu ul ul {
display: none;
}
#cssmenu > ul > li.active > ul {
display: block;
}
.align-right {
float: right;
}
#cssmenu > ul > li > a {
padding: 16px 22px;
cursor: pointer;
z-index: 2;
font-size: 16px;
text-decoration: none;
color: #ffffff;
-webkit-transition: color .2s ease;
-o-transition: color .2s ease;
transition: color .2s ease;
}
#cssmenu > ul > li > a:hover {
color: #d8f3f0;
}
#cssmenu ul > li.has-sub > a:after {
position: absolute;
right: 26px;
top: 19px;
z-index: 5;
display: block;
height: 10px;
width: 2px;
content: "";
-webkit-transition: all 0.1s ease-out;
-moz-transition: all 0.1s ease-out;
-ms-transition: all 0.1s ease-out;
-o-transition: all 0.1s ease-out;
transition: all 0.1s ease-out;
}
#cssmenu ul > li.has-sub > a:before {
position: absolute;
right: 22px;
top: 23px;
display: block;
width: 10px;
height: 2px;
content: "";
-webkit-transition: all 0.1s ease-out;
-moz-transition: all 0.1s ease-out;
-ms-transition: all 0.1s ease-out;
-o-transition: all 0.1s ease-out;
transition: all 0.1s ease-out;
}
#cssmenu ul > li.has-sub.open > a:after,
#cssmenu ul > li.has-sub.open > a:before {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
#cssmenu ul ul li a {
padding: 14px 22px;
cursor: pointer;
z-index: 2;
font-size: 14px;
text-decoration: none;
color: #dddddd;
-webkit-transition: color .2s ease;
-o-transition: color .2s ease;
transition: color .2s ease;
}
#menu ul li:hover a {
color: pink;
}
#cssmenu ul ul ul li a {
padding-left: 32px;
}
#cssmenu ul ul li a:hover {
color: #ffffff;
}
#cssmenu ul ul > li.has-sub > a:after {
top: 16px;
right: 26px;
}
#cssmenu ul ul > li.has-sub > a:before {
top: 20px;
}
.menu {
margin: 0 auto;
padding: 0;
width: 350px;
}
.menu li {
list-style: none;
}
.menu li a {
display: table;
margin-top: 1px;
padding: 14px 10px;
width: 100%;
text-decoration: none;
text-align: left;
vertical-align: middle;
color: #ccc;
font-weight: 600;
font-size: 18px;
overflow: hidden;
-webkit-transition-property: background;
-webkit-transition-duration: 0.4s;
-webkit-transition-timing-function: ease-out;
transition-property: background;
transition-duration: 0.4s;
transition-timing-function: ease-out;
}
.menu > li:first-child a {
margin-top: 0;
}
.menu >li a:hover a:first-child {
font-size: 25px;
color: #547b16;
}
.menu li a:hover {
] -webkit-transition-property: background;
-webkit-transition-duration: 0.2s;
-webkit-transition-timing-function: ease-out;
transition-property: background;
transition-duration: 0.2s;
transition-timing-function: ease-out;
}
.menu li ul {
margin: 0;
padding: 0;
}
.menu li li a {
display: block;
margin-top: 0;
padding: 0 10px;
height: 0;
color: #1F3D39;
-webkit-transition-property: all;
-webkit-transition-duration: 0.5s;
-webkit-transition-timing-function: ease-out;
transition-property: all;
transition-duration: 0.5s;
transition-timing-function: ease-out;
}
.menu > li:hover li a {
display: table;
margin-top: 1px;
padding: 10px;
width: 100%;
height: 1em;
-webkit-transition-property: all;
-webkit-transition-duration: 0.3s;
-webkit-transition-timing-function: ease-out;
transition-property: all;
transition-duration: 0.3s;
transition-timing-function: ease-out;
}
.menu > li:hover li a:hover {
-webkit-transition-property: background;
-webkit-transition-duration: 0.2s;
-webkit-transition-timing-function: ease-out;
transition-property: background;
transition-duration: 0.2s;
transition-timing-function: ease-out;
}
.menu > li li a:hover {
color: pink;
}
<nav id="menu_box">
<ul class="menu">
<li> <a href="#">Menu</a>
<ul>
<li><a href="#">sub</a>
</li>
<li><a href="#">sub</a>
</li>
<li><a href="#">sub</a>
</li>
</ul>
</li>
<li> <a href="#">Menu</a>
<ul>
<li><a href="#">sub</a>
</li>
<li><a href="#">sub</a>
</li>
<li><a href="#">sub</a>
</li>
</ul>
</li>
<li> <a href="#">Menu</a>
<ul>
<li><a href="#">sub</a>
</li>
<li><a href="#">sub</a>
</li>
</ul>
</li>
</ul>
</nav>
关于html - 当悬停并瞄准第一个 child 时,如何瞄准 Accordion li?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30946783/