for the search, my way to preload images! haha

Search for in

Resize images using :hover

CSS Coding Tutorials | Submited Feb 16, 2008

Written by: User Picture..

How to clip/resize images, and unclip/unresize them when you hover over them. :)

<tutorial>


HTML



<div class="imgBox">
<a href="#"><img src="http://j6.bz/5im.jpg" class="hoverIMG" /></a>
</div>

<div class="imgBox">
That creates a DIV box named imgBox, it holds the image.

<a href="#">
I added the <a> tag so that the :hover pseudo element works as it should in all browsers. when the href is set to "#" or "/" it does nothing, it's just an inactive clickable thing.

<img src="http://j6.bz/5im.jpg" class="hoverIMG" />
That adds the image, and to be specific I added a class name to it (hoverIMG) in case you wanted to do this different ways with different pictures.

The rest are closing tags for the link and the DIV.

CSS

[Style Tags]

.imgBox{overflow:hidden; width:100px; height:100px;}
.imgBox a img.hoverIMG{width:100px;}
.imgBox a:hover img.hoverIMG{width:auto; position:absolute;}

Now to explain:
.imgBox{overflow:hidden; width:100px; height:100px;}
That makes the DIV box containing the image a 100px square, and anything in the box that exceeds it will be hidden.

.imgBox a img.hoverIMG{width:100px;}
That scales the image so that it's 100px in width, however, it still gets cut off a bit inside the DIV box height wise.

.imgBox a:hover img.hoverIMG{width:auto; position:absolute;}
Since I added :hover to the A element, it only affects when the mouse hovers over the link/image.
width:auto; means that when you hover it it'll go to it's original size.
position:absolute; brings it outside of the box so you can see the full image.

</tutorial>


tags Tags: resize scale images when hovered

0Thumbs up  Thumbs down0

Related Tutorials
Adding Glitter to Images
Images in HTML
Text / Image Reflection
Myspace URL box images
Resize comment images [skem9]
Image hovers
Preload Images
Resize images using :hover
Randomness with PHP
PSP : MAKING IMAGES TRANSPARENT (TUT 2)
PSP : MAKING IMAGES TRANSPARENT (TUT 3)
How to get Header images in a Friendster Layout
Creating "Your IP is" images
Random Images
1 Comments
  User Picture.. ~ 06/13/08, 3:41am
Picture..
examples?

1 


Sorry, you have to be a member to comment tutorials