How to keep list item in active state while hovering on dropdown list?

I create a dropdown menu on my website and more or less successfully completed a task other than one thing.

When you hover over the drop-down menu, the state of the hang of the main menu link disappears due to the fact that I no longer hang on it.

How can I keep the style of the active state in the link when I hover over the dropdown items?

I copied the code http://cssdesk.com/PZBM2 if you hover over the first element of the list, where you will see the hang state that I'm talking about, and a dropdown.

Here is the code also:

/*Main nav*/
.main_nav_container{
    margin-top:10px;
    margin-bottom:10px;
    display:block;
    float:right;
}
ul.main_nav{
    margin:0;
    padding:0;
}
ul.main_nav li{
    display:inline-block;
    margin:0;
    padding:0;
}
ul.main_nav li a{
    font-size:13px;
    display:block;
    font-weight:bold;
    position:relative;
    height:25px;
    line-height:25px;
    padding:0 13px;
    text-decoration:none;
    color:#1122cc;
    border:1px solid transparent;
}
ul.main_nav li a:hover{
    text-decoration:underline !important;
    border-top:solid 1px #ccc;
    border-left:solid 1px #ccc;
    border-right:solid 1px #ccc;
}
ul.main_nav li ul{
    display:none;
    position:absolute;
    background: #fff;
    margin:0;
    padding:0;
    border:solid 1px #ccc;
    -moz-border-radius: 4px;
    -webkit-border-radius: 4px;
    -khtml-border-radius: 4px;
    border-radius: 4px;
}
ul.main_nav li ul:hover #hover{
    border:#ccc 1px solid;
}
ul.main_nav li ul li{
    display:block;
    margin:0;
    padding:0;
    text-align:left;
}
ul.main_nav li ul li a{
    font-weight:normal;
}
ul.main_nav li:hover ul{
    display:inline;
}

HTML

<div class="main_nav_container">
    <ul class="main_nav">
        <li>
            <a id="hover" href="#">For sale</a>
            <ul>
                <li><a href="#">Property for sale</a></li>
                <li><a href="#">New homes for sale</a></li>
                <li><a href="#">Find estate agents</a></li>
            </ul>
        </li>
        <li><a href="#">To rent</a></li>
        <li><a href="#">New homes</a></li>
        <li><a href="#">House prices</a></li>
        <li><a href="#">Blog</a></li>
        <li><a href="#">Property advice</a></li>
        <li><a href="#">Contact</a></li>
    </ul>
</div>
+5
source share
1 answer

you must replace

ul.main_nav li a:hover{
    text-decoration:underline !important;
    border-top:solid 1px #ccc;
    border-left:solid 1px #ccc;
    border-right:solid 1px #ccc;
}

with

ul.main_nav li:hover{
    text-decoration:underline !important;
    border-top:solid 1px #ccc;
    border-left:solid 1px #ccc;
    border-right:solid 1px #ccc;
}

in your css. Enjoy! :)

+7
source

All Articles