Trapo
Trapo

Reputation: 17

Why is my :hover not working?

Hi I am trying to build a menu with different levels. When I try to hover over my li item to show the next level, it does not work.

Can any one help me please?

The code for the CSS is :

/********************* RESET  ********************/
.menu, .memu ul{
    margin:0;
    padding: 0;
    list-style: none;
}

/********************* MENU ITEMS  ********************/
.menu > li {float:left;}

.menu > li.floatr{float:right;}

.menu li{position:relative;}

.menu li > a{display:block;}

/********************* SUB MENU  ********************/

.menu ul{
    display:none;
    position:absolute;
    width:125px;
}

.menu li:hover > ul {display:block;}

.menu ul ul{
    top:0px;
    left:125px;

}

.menu > li.floatr > ul {right:0;}
.menu > li.floatr > ul ul {left:-125px;}

And the html is:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Menu</title>

    <link rel="stylesheet" href="css/style.css">
</head>
<body style="padding:20px;">
    <ul class="menu">
        <li><a href="#">Blog</a></li>
        <!-- strat level 2 -->
            <ul>
                <li><a href="#">Add post</a></li>
                <li><a href="#">Archive</a></li>
                    <!-- start level 3 -->
                        <ul>
                            <li><a href="#">By Author</a></li>
                            <li><a href="#">By Year</a></li>
                            <li><a href="#">By Category</a></li>
                        </ul>
                    <!-- end level 3 -->

                <li><a href="#">Comments <span class="bubble">50</span></a></li>
            </ul>
        <!-- end level 2 -->
        <li><a href="#">Products</a></li>


        <li><a href="#">Messages <span class="bubble-alt">4</span></a></li>

        <li><a href="#">Updates <span class="bubble">23</span></a></li>

        <li class="floatr"><a href="#">Envanto</a></li>
        <li class="floatr"><a href="#">Social</a></li>
            <!-- strat level 2 -->
                <ul>
                    <li><a href="#">Twitter</a></li>
                    <li><a href="#">Facebook</a></li>
                    <li><a href="#">Google+</a></li>
                </ul>
            <!-- end level 2 -->
    </ul>
</body>
</html>

Upvotes: 0

Views: 178

Answers (1)

LeBen
LeBen

Reputation: 2049

You're actually targeting an unordered-list inside a list-item with .menu li:hover > ul.

But in your HTML, your <ul> isn't inside the <li>, it's after.

You can modify your HTML to fit the CSS selector by putting the <ul> inside the previous <li> or you can use the adjacent sibling selector (+) instead .menu li:hover + ul.

Upvotes: 6

Related Questions