Silver007 Silver007 - 1 month ago 8
HTML Question

IE7: Hover an Image will show another image at different place

I have a few images one on top of each other in a form of a "menu".

I would like that while I hover one of the images, it will show another image.
I also would like that while hovering each image, it will go up by 5px (currently it does not).

It must support Internet Explorer 7 or higher.

I hope what I have requested is possible and really appreciate any help you can provide.

My code so far:



.hw { font-size: 50px; padding: 50px; }

.first {
position: relative;
top: 0;
left: 0;
}

.second {
position: absolute;
right: 180px;
}

.third {
position: absolute;
right: 360px;
}

.logo {
position: relative;
bottom:60px;
left: 100px;
}

.first:hover, .second:hover, third:hover {
bottom: 5px;
}

.hidden {
display: none;
}

.logo:hover .hidden {
display: block;
}

<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body dir="rtl">

<p class="hw">Hello World!</p>


<img class="hidden" src="http://i.imgur.com/MY5bRT1.jpg" style="position: relative; bottom: 80px; right: 500px;"/>

<div style="position: relative; left: 0; top: 0;">
<img class="first" src="http://i.imgur.com/cr2cqPA.png"/>
<img class="second" src="http://i.imgur.com/MY5bRT1.jpg"/>
<img class="third" src="http://i.imgur.com/cr2cqPA.png"/>
<img class="logo" src="http://i.imgur.com/MY5bRT1.jpg"/>
</div>

</body>
</html>





EDIT: solution:



.hw {
font-size: 50px;
padding: 50px;
}

.menu {
margin-right:300px;
}

.first {
position: relative;
top: 0;
}

.second {
position: absolute;
right: 180px;
}

.third {
position: absolute;
right: 360px;
}

.forth {
position: absolute;
right: 540px;
}

.logo {
position: relative;
bottom:60px;
left: 100px;
}

.first:hover, .second:hover, .third:hover, .forth:hover {
margin-top: 3px;
}

.img-con {
position: relative;
width: 300px;
padding-top: 50px;
z-index: 9998;
}

.img-con > img {
position: absolute;
top: 0;
left: 0;
}

.img-con > img.logo {
z-index: 1;
}

.img-con:hover > img.logo {
z-index: -1;
margin-top: 3px;
}

.img-con:hover > img.hidden {
top: -100px;
right: 500px;
}

<!DOCTYPE html>
<html>
<head>
<title>טייסת מנ"ט</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body dir="rtl"><div class="center">
<p class="hw">Hello World!</p>

<div class="menu" style="position: relative; left: 0; top: 0;">
<div class="img-con">
<img class="logo" src="http://i.imgur.com/cr2cqPA.png"/>
<img class="hidden" src="http://i.imgur.com/MY5bRT1.jpg"/>
</div>

<img class="first" src="http://i.imgur.com/cr2cqPA.png"/>
<img class="second" src="http://i.imgur.com/MY5bRT1.jpg"/>
<img class="third" src="http://i.imgur.com/cr2cqPA.png"/>
<img class="forth" src="http://i.imgur.com/MY5bRT1.jpg"/>
</div>
</div></body>
</html>




Answer

I found a solution for you. You need insert every two image to container and set him with Relative position. Your images sets by Absolute position and you can play with there z-index on :hover to get the resolute.

Here we go:

.img-con {
  position: relative;
  width: 400px;
  margin: 20px;
}

.img-con > img {
  position: absolute;
  top: 0;
  left: 0;
}

.img-con > img.first {
  z-index: 1;
}

.img-con:hover > img.first {
  z-index: -1;
}

.img-con:hover > img.second {
  top: -5px;
  left: 5px;
}
<div class="img-con">
    <img class="first" src="http://i.imgur.com/cr2cqPA.png"/>
    <img class="second" src="http://i.imgur.com/MY5bRT1.jpg"/>
</div>