posted on:February 14, 2008
Create Resizing Thumbnails Using Overflow Property
This tutorial is aimed at controlling the size of the thumbnails appearing on your page. Sometimes we don’t have enough space to spare to fit in large thumbnails and yet we would like to avoid small and barely recognizable images. Using this trick we limit the default dimensions of the thumb, and show it in full size when user mouse-overs it.
Take a look at the demo
| Download zip file
Overview
What we have here is not actual image resizing. It is a resizing of the thumb’s visible area on mouse over. How do we do that? Using overflow property!
The overflow property defines the appearance of the content when it overflows the container area. If the container has limited size, for one reason or another, then we use overflow to define what happens. Possible values of overflow property are visible, hidden, scroll and auto. It’s the combination of these values that we will use here and make this trick work. Basically, we will hide a part of the thumbnail when in default state, and show it entirely on mouse over.
The Concept
The idea behind this is, to place an image into a certain container. Since we’re talking about thumbnails that container would be an <a> tag. We set the size (width and height) of the container to desired values and we set the position property of the container to relative. Image inside has an absolute position. We use negative top and left values to offset the image. Container has overflow set to hidden so only a part of the image that is placed inside the container’s actual area will be visible. The rest of it will be hidden. On a:hover we set the container’s overflow to visible, and reveal entire image.
The Code
This trick can be used for thumbnail lists or single thumbnails, as shown on the demo page. For markup we use standard tags
<a href="#"><img src="image.jpg" alt="my image" /></a>
Definition of the default state for thumbnails would be something like this:
ul#thumbs a{ display:block; float:left; width:100px; height:100px; line-height:100px; overflow:hidden; position:relative; z-index:1; } ul#thumbs a img{ float:left; position:absolute; top:-20px; left:-50px; }
<a> tag has defined width and height to whatever fits into our site’s design. Also, overflow is set to hidden. We then play with negative top and left values to "crop" the image to a perfect fit. If you want to take this further, you can define cropping area for every single image you have in thumb list and target the area you would like to show.
ul#thumbs a img{ float:left; position:absolute; top:-20px; left:-50px; } ul#thumbs li#image1 a img{ top:-28px; left:-55px; } ul#thumbs li#image2 a img{ top:-18px; left:-48px; } ul#thumbs li#image3 a img{ top:-21px; left:-30px; } . . .
Now, when user mouse-overs it we set the overflow to visible:
ul#thumbs a:hover{ overflow:visible; z-index:1000; border:none; }
Note the z-index for both default and hovered container. This is very important because we want to place the hovered above it’s siblings. Otherwise it would be placed below and the trick wouldn’t be complete.
Enjoyed the article?
Then don't miss our next one! Subscribe to our RSS feed or share it with your friends.
Share on FacebookTweet thisDeliciousStumbleUpon RedditSubscribe
Comments (83 Comments)
Sorry, the comment form is closed at this time.
3kolone
February 14, 2008
Catar4x
February 14, 2008
Gloria
February 14, 2008
cssglobe
February 14, 2008
Ywg
February 14, 2008
cssglobe
February 14, 2008
EmanuelBlagonic
February 14, 2008
Philippine Goji Juice
February 15, 2008
Megan
February 15, 2008
flisterz
February 15, 2008
mbhayes
February 15, 2008
Brian Rock
February 15, 2008
Eric Wendelin
February 16, 2008
Pozycjonowanie
February 16, 2008
bojan
February 16, 2008
Pepe
February 20, 2008
Sangesh
February 20, 2008
Shreemani
February 20, 2008
Tristan Bethe
February 20, 2008
kab
February 20, 2008
Dave
February 22, 2008
cssglobe
February 22, 2008
kab
February 24, 2008
Services Group
February 25, 2008
Tom
February 26, 2008
Pablo
February 27, 2008
varmisin yokmusun
February 28, 2008
is ilanlari
February 28, 2008
adriana mullen
February 29, 2008
Lewis David
March 7, 2008
Simon James
March 8, 2008
Forumistan
March 14, 2008
polarizer
March 19, 2008
Mike
March 21, 2008
Muhammad Usman
March 25, 2008
Val
April 10, 2008
AG
April 16, 2008
AG
April 16, 2008
oyunlar
April 19, 2008
kuaför malzemeleri
May 7, 2008
Sim Kamsan
May 20, 2008
herzausgold
May 21, 2008
b
May 21, 2008
Alex
May 27, 2008
Don
June 5, 2008
Pepe
June 12, 2008
Astyan Tanks Bitter
June 14, 2008
josterr
June 19, 2008
Ionut Bucur
June 25, 2008
Zim
July 8, 2008
Oyun
July 9, 2008
Michael Study
July 9, 2008
utility warehouse
July 21, 2008
toner
August 12, 2008
Otel
September 4, 2008
Dominic Turner, Bristol
November 12, 2008
Estetik
November 16, 2008
Estetik
November 25, 2008
film izle
November 28, 2008
chat
December 6, 2008
savaÅŸ oyunu
December 27, 2008
oyun
December 31, 2008
sproutysem
January 3, 2009
Luciano Santa BrÃgida
January 5, 2009
komik oyunlar
January 27, 2009
giysi giydirme oyunlari
January 27, 2009
Rik Weber
February 5, 2009
GazTruman
February 9, 2009
Seo
March 2, 2009
haberler
March 2, 2009
sinava hazirlik
March 2, 2009
ÅŸiÅŸme park
March 2, 2009
alex
March 6, 2009
Matt
March 16, 2009
Hosting
March 18, 2009
chat
March 19, 2009
burun estetigi
March 26, 2009
craig
March 29, 2009
Az
April 13, 2009
p31m
April 29, 2009
Clark Smith
May 29, 2009
suvish
June 3, 2009
sohbet chat
June 21, 2009