I have 5 “experts” (just a square div) that are to be overlapped and layered over each other. On mouse over, that card should come to the front and change a few other CSS properties. Upon mouse out, it should return to its original state.
My code works fine in FF, Chrome, IE8 and even Quirks mode (now thats surprising!) but fails in IE7. I’ve done a bunch of reading about the infamous “ie7 z index bug” but haven’t found anything that applies to my own situation. All the readings I found have been for navigation style elements, but that doesn’t really apply to me.
I believe it has something to do with hover state in IE, but besides that I’m not sure.
I did find out that if I use jquery to do the hover state, it works fine in IE7! But in attempt to understand IE and become a better developer, I’d like to find a CSS only solution to this. I’ve included the jquery (commented out) to make it work, for reference (also don’t forget to comment out the CSS hover state labeled in the comment, or else funny things will happen).
<html>
<head>
<style type="text/css">
#experts .inner {position: relative; z-index:1;}
.expert {width: 245px; height: 333px; position: absolute; }
.expert a {width: 245px; height: 333px; display: block; text-indent: -9999px; }
#expert1 {left: 0; top: 0; z-index: 3;}
#expert1 a {background-color: #FC8B8B;}
#expert1 a:hover {background-color: #ff0000;}
#expert2 {left: 160px; top: 0; z-index: 4;}
#expert2 a{background-color: #E57DFA;}
#expert2 a:hover {background-color: #D200FC;}
#expert3 {left: 320px; top: 0; z-index: 5; }
#expert3 a{background-color: #7A83FF;}
#expert3 a:hover {background-color: #0011FF;}
#expert4 {left: 500px; top: 0; z-index: 6; }
#expert4 a{background-color: #8EFF80;}
#expert4 a:hover{background-color: #1DFA00;}
#expert5 {left: 670px; top: 0; z-index: 7; }
#expert5 a{background-color: #FAC882;}
#expert5 a:hover{background-color: #FF9500;}
#expert1 ,#expert3 ,#expert5 {top: 50px;}
/** COMMENT THIS SECTION OUT WHEN USING JQUERY **/
#expert1:hover,
#expert2:hover,
#expert3:hover,
#expert4:hover,
#expert5:hover {z-index: 10;}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<div id="experts">
<div class="inner">
<div id="expert1" class="expert"><a href="#">Expert 1</a></div>
<div id="expert2" class="expert"><a href="#">Expert 2</a></div>
<div id="expert3" class="expert"><a href="#">Expert 3</a></div>
<div id="expert4" class="expert"><a href="#">Expert 4</a></div>
<div id="expert5" class="expert"><a href="#">Expert 5</a></div>
</div>
</div>
<script>
/*
(function ($) {
var old = 0;
$('.expert').hover(
function(){
old = $(this).css('z-index');
$(this).css('z-index', 10);
console.log($(this).css('z-index'));
},
function(){
$(this).css('z-index', old) ;
console.log($(this).css('z-index'));
});
} (jQuery));
*/
</script>
</body>
</html>
Any help or guidance is greatly appreciated.
Feel free to ask questions too!!
Thanks in advance!!