Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Roven Loo
7,834 PointsParent object won't stay hovered when children are hovered
So I'm trying to make this nav menu but the parent won't stay hovered when children are hovered. How do I keep the parent hovered?
<ul class="ul-wrap">
<li>
<a href="#"><div class="list-div">
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
<line class="left" x1="0" y1="0" x2="0" y2="-23"/>
</svg>
My Portfolio
</div></a>
<ul class="submenu">
<li><a href="#">Web</a></li>
<li><a href="#">Graphic</a></li>
<li><a href="#">Others</a></li>
</ul>
</li>
</ul>
a {
text-decoration: none;
color:#666666;
}
.ul-wrap {
display: block;
float:left;
list-style-type: none;
text-align: right;
margin-top: 35px;
}
.ul-wrap li{
margin-top: 12px;
font-size: 1.08em;
display: inline-block;
}
.list-div {
padding-left: 14px;
position: relative;
}
/* cool border effect thing*/
.list-div svg {
position: absolute;
top: 0;
left: 0;
}
.list-div svg line {
stroke-width: 6;
stroke: #2bc2c4;
fill: none;
-webkit-transition: all 0.08s ease-in-out;
transition: all 0.08s ease-in-out;
}
.list-div svg line.left {
stroke-dasharray: 490 400;
}
.list-div:hover svg line.left {
-webkit-transform: translateY(23px);
transform: translateY(23px);
}
/*----*/
.submenu {
list-style-type: none;
font-size: 0.85em;
margin-top: 0px;
padding: 0;
}
.submenu li {
display: block;
margin-top: 5px;
color: rgba(255, 255, 255, 0.7);
}
.submenu li a:hover{
border: none;
color: #2bc2c4;
}
Thanks in advance for answering :)
1 Answer
Adam Mould
5,458 PointsChange the following line in your CSS
.list-div:hover svg line.left {
-webkit-transform: translateY(23px);
transform: translateY(23px);
}
to this
.ul-wrap > li:hover .list-div svg line.left {
-webkit-transform: translateY(23px);
transform: translateY(23px);
}
This will target the parent list item (li) as the hover state instead, which will remain active when hovering any child lists.
Roven Loo
7,834 PointsRoven Loo
7,834 PointsOhhh that makes sense. Thank you very much for helping, it works perfectly! Cheers :)