Welcome to WebmasterWorld Guest from

Forum Moderators: not2easy

Message Too Old, No Replies

Image Hover which links to page problem

1:33 pm on Jun 2, 2012 (gmt 0)

New User

joined:May 10, 2012
posts: 8
votes: 0


Basically I want something like this...http://www.devirtuoso.com/Examples/CSS-Image-Viewer/.

The only difference is how the images appear and hover.

I basically want the images to change on hover, not when clicked. Then when clicked I want it to go to a different page.

I wondered if anybody could help me.

I remember a while ago I could do something where by you hover over an image somewhere on the page, and it would pop up another image on the page. I'm not talking over the original like a link, but anywhere I want. Could someone share any light or link to any articles online? I'm having trouble finding information.

The only other example I've found is this ...


But I swear you can do it without being so complicated like that.


Basically... this is what I want to do.


Where you see the grey slightly transparent boxes over the image on the background. I want it so when you hover over those the bg image changes. Those grey boxes will eventually have wording in them and when you hover over that particular word the background image changes to a picture that has something to do with that word.

I still would like the grey boxes to stay on top though, but the image to change (currently a pcb).

At the moment it's just a div with an image background written in the css. The grey boxes are in the html as linked images (so when they are clicked they visit another page).
11:21 pm on June 5, 2012 (gmt 0)

Junior Member

joined:June 5, 2012
votes: 0

You can do this very easily with some javascript ie.

<a href="example.html" OnMouseOver = "document.images.example.src= 'example-hover.jpg'" OnMouseOut ="document.images.example.src='example.jpg'" ><img src="example.jpg" alt="example" name="example" /></a></p>
3:52 pm on June 6, 2012 (gmt 0)

New User

joined:June 5, 2012
posts: 8
votes: 0

You could use something like this:

<script type="text/javascript">

function alternateImage() {
document.getElementById("yourImageID").src = "alternateImage.jpg";
function defaultImage() {
document.getElementById("yourImageID").src = "yourDefaultImage.jpg";


<a href="#" onmouseover="alternateImage();" onmouseout="defaultImage();" ><img id="yourImageID" src="yourDefaultImage.jpg" /></a>
1:45 pm on June 8, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Aug 9, 2008
posts: 961
votes: 0

Hi tetsuo3, you are right this does not need to be that complicated, and if I understand what you want correctly, you don't need javascript to achieve this. What I think you want is a type of image change on hover. Check out the photo galleries at stu nicholls for lots of working examples.

What you have sounds like a list of links. so rather than using a div, mark it up using an unordered list. Make the <ul> the dimensions of the images that will change on hover. (You can also set a default background-image for when users enter the page.) Put the image that will show on hover inside the <a>, then hide it. Then make it visible on hover. The following code should give you a start:

<li><a href="#">Word 1<img src="image1.jpg" alt="" ></a></li>
<li><a href="#">Word 2<img src="image2.jpg" alt=""></a></li>
<li><a href="#">Word 3<img src="image3.jpg" alt=""></a></li>

ul {
/*The dimensions of the images */
/*make the menu relative so the images take their position from here*/
/*explicitly setting z-index allows you to control the value for the child elements so you can display the image above the default background, but behind the link */

li {

a {
/* style the links */

a img {
/* hide the image until a hover - */
/* make it small so it takes up no space */
/*set the position for when it is hovered */

/* style the link on hover */
a:hover {

/* make the image visible on hover */
a:hover img {