0

I'm trying to swap an image logo with text on mouse hover.

I have been looking at jquery and css to create this transition, but I haven't been lucky with finding a solution. Hopefully you can help me out a bit.

This is what I'm stuck with.

Example http://jsfiddle.net/VugzA/

HTML

<div id="logo">
<ul>
    <li>
        <a href="#home" title="Back to Home?">                        

            <span class="logo_icon">
                <img src="some.gif" alt="Logo image" width="45" height="55" />
            </span>

            <span class="text">Some Text</span>

        </a>
    </li>
</ul>
</div>

CSS

#logo ul {
list-style: none;
margin-left: -20px;
}

.logo_icon {
display: block;
} 

.logo_icon:hover {
display: none;
}

.text {
display: none;
}

.logo_icon:hover + .text {
display: block
}

1 Answer 1

4

Here is an update to your fiddle

Updated html:

<div id="logo">
<a href="#home" title="Back to Home?">                        
<span class="logo_icon">
<img src="some.gif" alt="Logo image" width="45" height="55" />
</span>
<span class="text">Some Text</span>
</a>
</div>

and updated css:

.logo_icon {
    display: block;
} 
.text {
    display: none;
}
#logo a:hover .logo_icon
{
    display:none;
}
#logo a:hover .text
{
    display:block;
}

What i do here is tie the hover event on the link instead of like you did (hover on image and text), and the image and text span are children of that element. So, when you hover on the link, the specific styles apply.

Sign up to request clarification or add additional context in comments.

4 Comments

if this answers your question, please mark it as an answer :)
Please explain why this works and also see meta.stackexchange.com/questions/145987/…
Thanks for mention this @andyb. i wasnt aware of that :)
This is a demo modified from @trajce.. maybe it helps

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.