当鼠标悬停在列表项的:before
上时,我希望对first-child
元素生效,以便代码
li:first-child:hover ul:before { Code here }
要更清楚地看到here中的代码或参见下面的
(我希望对.sub1-ul:before
)
* {
box-sizing: border-box;
text-decoration: none;
list-style-type: none
}
nav.nav-menu {
width:100%;
margin: 0 auto;
z-index: 2000;
}
ul.menu-wrapper {
position: relative;
width: 770px;
height: 90px;
padding-left: 100px;
padding-top: 15px;
margin: 0px auto;
z-index: 2000;
}
li.nav-item {
position: relative;
float: left;
margin-left: 30px
}
li.nav-item > a {
display: inline-block;
width: 150px;
height: 50px;
padding-top: 11px;
background-color: #3498DB;
color: #fff;
text-align: center;
font-weight: 600;
font-size: 19px;
border: 1px solid #5aabe1;
-webkit-transition: background-color 400ms, color 700ms ease-out;
-moz-transition: background-color 400ms, color 700ms ease-out;
transition: background-color 400ms, color 700ms ease-out
}
li.nav-item:hover > a {
background-color: #fffffc;
color: #3498db
}
/* ========== START SUB1 ========== */
.sub1-ul:before {
content: "";
display: inline-block;
position: relative;
width: 0px;
top: 15px;
left: 30px;
border-width: 0px 15px 15px 0px;
border-color: #0f0 #0F8FD3 transparent #000;
border-style: solid solid solid solid;
transform: rotate(-45deg)
}
.sub1-ul li:first-child:hover .sub1-ul:before {
content: "";
display: inline-block;
position: relative;
width: 0px;
top: 15px;
left: 3px;
border-width: 0px 15px 15px 0px;
border-color: #0f0 #000 transparent #000;
border-style: solid solid solid solid;
transform: rotate(-45deg)
}
.sub1-ul {
position: absolute;
top: 50px;
width: 100%;
height: 0;
margin-top:-10px ;
visibility: hidden;
overflow: hidden;
opacity: 0;
z-index: 9999;
-webkit-transition: all .2s linear;
-moz-transition: all .2s linear;
transition: all .2s linear
}
li.nav-item:hover .sub1-ul {
height: auto;
visibility: visible;
overflow: visible;
opacity: 1
}
.sub1-item {
position: relative;
top: -1px;
left: -36%;
width: 150px;
margin-top: 3px;
-webkit-transition:margin-left 200ms linear;
-moz-transition:margin-left 200ms linear;
transition:margin-left 200ms linear
}
.sub1-item:hover {
margin-left: 4px;
}
.sub1-item .sub1-a {
display: inline-block;
width: 150px;
height: 50px;
padding-top: 15px;
background-color: #0F8FD3;
text-align: center;
color: #fff;
font-size: 17px;
border-left: 6px solid #4C4C4C;
-webkit-transition: background-color 400ms,
border-left-color 400ms,
padding-left 200ms linear;
-moz-transition: background-color 400ms,
border-left-color 400ms,
padding-left 200ms linear;
transition: background-color 400ms,
border-left-color 400ms,
padding-left 500ms linear
}
.sub1-item:hover .sub1-a {
padding-left: 6px;
border-left-color: #e67e22;
}
/* ========== START SUB2 ========== */
.sub2-ul {
position: absolute;
top: 0px;
left: 100%;
width: 150px;
padding: 0;
margin: 0;
visibility: hidden;
overflow: hidden;
opacity: 0;
-webkit-transition: all 400ms ease;
-moz-transition: all 400ms ease;
transition: all 400ms ease
}
.sub1-item:hover .sub2-ul {
height: auto;
visibility: visible;
overflow: visible;
opacity: 1
}
.sub2-item {
position: relative;
margin-bottom:2px;
}
.sub2-item:hover {
border-left-color: #4c4c4c
}
.sub2-item .sub2-a {
display: inline-block;
width:150px;
height:50px;
margin-left: 1px;
padding-top:15px;
background-color: #3498DB;
color: #fff;
text-align: center;
font-size: 17px;
font-weight: normal;
border-left: 5px solid #e67e22;
-webkit-transition:all 200ms ease-in-out;
-moz-transition:all 200ms ease-in-out;
transition: all 200ms ease-in
}
.sub2-item:hover .sub2-a {
border-left-color: #4c4c4c
}

<nav id="sec-nav" class="nav-menu">
<ul class="menu-wrapper">
<li class="nav-item"><a href="#"> Menu1 </a>
<ul class="sub1-ul">
<!-- ===== Want to move before with this list item when mouseover on it =====-->
<li class="sub1-item">
<a class="sub1-a" href="#"> sub menu </a>
<ul class="sub2-ul">
<li class="sub2-item"><a class="sub2-a" href="#"> sub menu2 </a>
</li>
<li class="sub2-item"><a class="sub2-a" href="#"> sub menu2 </a>
</li>
<li class="sub2-item"><a class="sub2-a" href="#"> sub menu2 </a>
</li>
<li class="sub2-item"><a class="sub2-a" href="#"> sub menu2 </a>
</li>
</ul>
</li>
<!--================ Ens of the list item ======================== -->
<li class="sub1-item">
<a class="sub1-a" href="#"> sub menu </a>
<ul class="sub2-ul">
<li class="sub2-item"><a class="sub2-a" href="#"> sub menu2 </a>
</li>
<li class="sub2-item"><a class="sub2-a" href="#"> sub menu2 </a>
</li>
<li class="sub2-item"><a class="sub2-a" href="#"> sub menu2 </a>
</li>
<li class="sub2-item"><a class="sub2-a" href="#"> sub menu2 </a>
</li>
</ul>
</li>
<li class="sub1-item"><a class="sub1-a" href="#"> sub menu </a>
</li>
<li class="sub1-item"><a class="sub1-a" href="#"> sub menu </a>
</li>
<li class="sub1-item"><a class="sub1-a" href="#"> sub menu </a>
</li>
</ul>
</li>
<li class="nav-item"><a href="#"> Menu2 </a>
</li>
<li class="nav-item"><a href="#"> Menu3 </a>
</li>
</ul>
</nav>
&#13;