Jump to content

On hover, show image at its original size?


galvin

Recommended Posts

I have code like this for many images, where the image size is always set to 50 pixels wide...

<a href='#' class="image"><img src="images/pic1.jpg" width=50></a>

 

Then I use CSS so that users can hover over the 50x50 image and have a bigger image show up, using...

 

Then I have this CSS for it...

a.image:hover img {
position: absolute;
        width: 200px;
z-index: 10000;
}

 

This code works perfectly. However, I don't necessarily want the hovered image to always be 200px. If the original image is 400px, I want it to be 400px. If the original image is only 120px, I want it to be 120px.

 

Is there anyway to do this in CSS. I tried "height: auto;" and that doesn't do it.

 

Any thoughts?

 

Link to comment
Share on other sites

well you need to remove the inline style because it will overwrite your properties set in the external stlyesheet i suppose.

maybe tryout this:

a.image img {
      width:50px;
   }

a.image:hover img {
   position: absolute;
        width: 100%; /* maybe even try auto */
   z-index: 10000;
   }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.