1

Im trying to make a div change when I hover on another div. I have done this a million times before but for some reason I just can not see why this one isnt working.

CSS

#floatimg:hover > #float_tools
{
opacity: 1;
}
#float_tools
{
width: 150px;
margin: auto;
opacity: 0.3;
}

HTML

<div id='floatBox'>
        <div id='float_image'>
            <img id="floatimg" src="">
        </div>
        <div id='float_tools'>
            <div id='float_prev'><a href='javascript:void' onclick=''><img src='images/Button_Prev.png' width='50px'></a></div>
            <div id='float_close'><a href='javascript:void' onclick=''><img src='images/close.png' width='50px'></a></div>
            <div id='float_next'><a href='javascript:void' onclick=''><img src='images/Button_Next.png' width='50px'></a></div>
        </div>
    </div>

2 Answers 2

1

It's simply because #float_tools div is not a direct child of #floatimg.

Try something like:

<div id='floatBox'>
        <div id='float_image'>
            <img id="floatimg" src="">
            <div id='float_tools'>
                <div id='float_prev'><a href='javascript:void' onclick=''><img src='images/Button_Prev.png' width='50px'></a></div>
                <div id='float_close'><a href='javascript:void' onclick=''><img src='images/close.png' width='50px'></a></div>
                <div id='float_next'><a href='javascript:void' onclick=''><img src='images/Button_Next.png' width='50px'></a></div>
            </div>
        </div>
    </div>

CSS:

#float_image:hover > #float_tools
{
opacity: 1;
}
#float_tools
{
width: 150px;
margin: auto;
opacity: 0.3;
}
Sign up to request clarification or add additional context in comments.

Comments

0

When you try to use the greater than sign (>), the affected element should be a direct child of the hovered element. In your HTML, the hovered element and the affected element are not directly related to each other.

It would be better this way:

#float_image:hover + #float_tools
{
opacity: 1;
}
#float_tools
{
width: 150px;
margin: auto;
opacity: 0.3;
}

Here is a fiddle

1 Comment

As you see, i applied the hover to the parent of the #floatimg, which is #float_image

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.