Sam
Sam

Reputation: 500

CSS: How do I hover over one element, and show another?

I have a navigation panel, and when you hover over the fixtures <div>, it displays the first 5 or so fixtures in a panel that drops down from the main navigation panel.

Im trying to achieve this using CSS with :hover. This is an example of the :hover im trying to get: http://jsfiddle.net/EajKf/189/

HTML:

<div id="nav">
    <ul id="menu">                
        <li><a class="home" href="#">Home</a></li>
        <li><a class="fixtures" href="#">Fixtures</a></li>
        <li><a class="hidden" href="#">Manchester City</a></li>             
    </ul>
</div>

CSS:

#nav li a.fixtures:hover{
        color: #000;
        margin-top:1px;
    -webkit-transition-duration: 0.4s;
    cursor: pointer;
    text-decoration: none;
    font-family: Arial, Helvetica, sans-serif;
    box-shadow: 0px 0px 20px rgba(0,235,255,0.8);
    -webkit-box-shadow: 0px 0px 20px rgba(255,102,51,0.8);
    background: rgba(255,102,51,0.8);
    opacity: 50%;
}
#nav li a.hidden{
     margin-top: 50px;
     padding: 100px;
     background-color: #fff;
     display: none;
}
#nav li a.fixtures:hover #nav li a.hidden{
    display: block;
}

Thanks for any answers!

Upvotes: 1

Views: 11518

Answers (2)

2507rkt3
2507rkt3

Reputation: 21852

you can do this by using the css 'inherit' value. check out this post and the demos within: http://joshnh.com/2012/10/25/dont-forget-the-css-value-inherit/

Upvotes: 0

Entity Black
Entity Black

Reputation: 3491

Did you mean this?

http://jsfiddle.net/EajKf/190/

html:

<div id="nav">
    <ul id="menu">                
        <li class="home"><a href="#">Home</a></li>
        <li class="fixtures"><a href="#">Fixtures</a></li>
        <li class="hidden"><a href="#">Manchester City</a></li>             
    </ul>
</div>

css:

#nav li.fixtures:hover{
        color: #000;
        margin-top:1px;
    -webkit-transition-duration: 0.4s;
    cursor: pointer;
    text-decoration: none;
    font-family: Arial, Helvetica, sans-serif;
    box-shadow: 0px 0px 20px rgba(0,235,255,0.8);
    -webkit-box-shadow: 0px 0px 20px rgba(255,102,51,0.8);
    background: rgba(255,102,51,0.8);
    opacity: 50%;
}
li.hidden{
     margin-top: 50px;
     padding: 100px;
     background-color: #fff;
     display: none;
}

li.fixtures:hover +  li.hidden{
    display: block;
}

EDIT:

it still doesn't work as you want... you have to make <li class="hidden"> child of <li class="fixtures">

Upvotes: 4

Related Questions