2

I am trying to add an image to a webpage which I have used CSS to do. The problem is that I've created a hover function which shows the right side of the image. This does works but when I add position: relative or the z-index: -1, the hover function just doesn't work. Is there any way around this problem without taking out position or z-

Thanks

http://jsfiddle.net/L5rvkt2g/

#logo {
        background: url(http://upload.wikimedia.org/wikipedia/commons/b/b9/1875_CC_double_eagle.jpg);
        width: 956px;
        height: 884px;
        background-position: left;
        margin: auto;
        position: relative;
        z-index: -1;
    }

        #logo:hover {
            background-position: right;
        }
1
  • Do you have to use -1? Can you not keep it at normal index and then shift whatever needs to be up? Commented Sep 24, 2014 at 15:20

3 Answers 3

1

The issue is about the z-index: -1; as the mouse can't hover index lower than 0, the hover doesn't work. Remove it and it'll work well !

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

5 Comments

Poorly worded answer. What does the mouse is at index 0 even mean?
@Adam Is this better ?
@Thomas no. Look at this example of a mouse hovering an element that has a z-index lower than 0: jsfiddle.net/ycrw02sd.
@canon - Trust me, I know exactly what I did, but my point was to negate the answerer's edit: the mouse can't hover index lower than 0
@Adam if you want to improve the answer, feel free to do it, as english is not my native language and I just know a few things in CSS, I didn't find the wise word to say and that's why I don't edit my answer (in order to not say another thing wrong) ;)
0

Lower layer cannot be hovered since it is covered by upper layer.

Just suppose in a bus, there are two window where you're sitting and you want to shake your hand outside the window. One window has glass and another has no glass, then you cannot shake your hand without opening the glass. That means the upper layer is blocking to get hovered.

Just bring your element upper-ward.

Comments

0

You are supposed to remove the z-index from your #logo and then your code works like a charm. Here is the working fiddle. This is to make sure that index of your img is 0 you can actually hover on your #logo.

Comments

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.