6

In below jquery function z-index is not working in IE7, Please help me

<script>
$(function() {
    $('span').hover(function() {

        $(this).stop().css({                      
            'float': 'left',
        'z-index':'15'
        }).animate({
            marginTop: '0px',
            marginLeft: '0px',            
            width: '200px',
            height: '125px',
            padding: '0px'

        }, 700, 'swing');


    }, function() {

        $(this).stop().css({            
            'border': '0px',
            'z-index':'10'
        }).fadeIn('slow').animate({
            marginTop: '0px',
            marginLeft: '0px',            
            width: '40px',
            height: '13px'            
        }, 700, 'swing');


    });
});

</script>

Help much appreciated. I am new to jquery.

2
  • 3
    Not working how? Can you provide a sample on jsfiddle? Commented May 31, 2011 at 14:46
  • 1
    I went ahead and put one together for you: jsfiddle.net/WacfY. I would help but i dont have IE7 on this comp. It works in Chrome11. Commented May 31, 2011 at 15:06

2 Answers 2

5

Is it only in IE7?

It looks like the issue is with the float:left in the first function.

As far as I know, z-index only works on positioned elements. Floats are not positioned and so cannot accept z-index. See http://reference.sitepoint.com/css/z-index

If possible, remove the float and position the span another way.

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

Comments

2

See http://www.brenelz.com/blog/2009/02/03/squish-the-internet-explorer-z-index-bug/ for an example of this bug. You have to give the parent element a higher z-index for it to work.

1 Comment

I think the parent element also has to have some sort of positioning, like position: relative.

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.