Kimler Sidebar Menu
Kimler Adventure Pages: Journal Entries
CSS Photo-Caption Zoom
Finally ...
On the left is a demonstration of the original version of photo-caption zoom. It's a pure-CSS, XHTML-valid, image/caption zoom method. Move the cursor over the image and it will 'zoom' (pop, explode, magnify) to reveal a larger image with a caption. There are a number of image rollover techniques, but this is the first that combines an image with a caption. It looks nice and saves page real estate, sitting as a small thumbnail, until the reader decides otherwise. Most important, the method is practical and easy to implement.
PZ3 Update: 10-Mar-2007 - Fixes for an IE7 bug (multiple right-floated images) & a work-a-round for IE6 and IE7 in quirks-mode.
Added July 2006: PZ3 is here! It's more robust, lighter and REPLACES PZ2. Compared to PZ2, PZ3 is easier to use, needs 72% less code, overcomes a pesky IE z-index problem and can use an infinite range of image sizes (image size is specified in the XHTML, not the CSS). Like PZ2, Photo-Caption Zoom version 3 overlays text. (See demo on the right).
Added Oct 2005: I've developed a more robust "version 2" (named "PZ2"). It adds functionality (and complexity) to the original, PLUS has the added capability to OVERLAY text (no more "element migration" on ZOOM). It is demonstrated here on the right.
A single image is used for both the small and large views. (No need to have a large and a small version). The width is the only size parameter needed (the surrounding <div> expands to the appropriate height). To float the image left or right and to use different images sizes, just use the appropriate class names from within the HTML (no need to modify an external CSS file).
This code is a result of my recent inspiration and chronic frustration regarding the presentation of images and photo captions on web pages. Below, you'll find 8 different image zoom techniques, all of which are demonstrated on their own page & include cut'n-paste CSS/HTML code. Take your pick.
They've been tested on a PC, using IE6(sp2) and FireFox(v1). I'm not sure how they'll render in different browsers or browser versions. All but two are pure-CSS solutions (two use JavaScript
) and all are XHTML-valid (verified with the 'validate' button on the footer bar).
Motivation
We've all seen this: "Click to see a larger version." (A new window takes over our screen and we wonder why the larger version is nearly the same size.) HTML makes it tough to present both thumbnail & full-scale versions of image data. If that's bad, it's even worse when it comes to the accompanying textual metadata - the caption.
Early on (or, in computer terms, the "Dark Ages") I used Microsoft Front Page to make my pages. Led by the nose, I merrily made large and small images, wondering just how tables could be effectively and efficiently used to render captions. I found a way, but it wasn't at all efficient. I ditched it because it was too cumbersome.
Why aren't caption tags associated with images and not tables? Who made that decision? Why can't one just add a caption attribute to the <img> tag, like 'alt' or 'title'? (I've used both as a captioning tool. It works, but only barely. There's no formatting and the bubble text disappears if you don't keep moving the cursor over the image).
A better way?
Because we just recently moved our pages from a free-host to a pay-host and began using "b2evolution" journaling software, we thought, "why not revisit the whole image-caption issue?" A Google search led me to "Simple Bits", where Dan Cederholm demonstrates a Photo Zoom example.
It zoomed a photo, without a caption, but it was pure-CSS. I downloaded the code & upon closer examination, quickly realized that this method was not practical, but it did provide inspiration & opened up several other avenues to examine.
More searching led me to two other sites: Paul Griffin presentes an elegantly simple and much more practical, technique; and Stu Nicholls at the "CSS Playground" demonstrates a unique CSS method to magnify an image and overlay it onto page text. Both methods showed promise of practicality, though neither dealt with a caption.
A picture may be worth a thousand words, but I've found that many pictures are mute when it comes to important things like "who", "when", "where" (and sometimes, surprisingly, even "WHAT"). An accompanying caption can add vital data to the visual image (metadata). But oddly, the lowly caption is often overlooked and not seen on web pages. Online photos are a lot like an 'inside joke'. Without the accompanying caption, you just don't 'get it' (to understand, 'you had to be there').
My search, didn't yield an 'out-of-the-box' solution. If there is a solution out there, I didn't find it. But, the three photo zoom techniques gave me hope that I might be able to design something on my own. That's what I did. Below are EIGHT different photo zoom techniques. Each one links to a demonstration page, which includes notes on the technique & cut'n-paste code. Three are merely replicas of the previous work (a synopsis and archive). Five are of my own making, two of which, are nearly identical (one uses javascript and the other doesn't) & offer practical solutions to the problem.
Photo-Only Zoom Methods
No. 1, A Pure-CSS Zoom - (Dan Cederholm's 'Proof-of-Concept')
No. 2, A Pure-CSS Zoom - (Paul Griffin's simple & elegant solution)
No. 3, A Pure-CSS Zoom - (Stu Nicholls' inventive method with text overlay)
No. 4, A Java/CSS Zoom - (My first time popping images - why use CSS?)
Photo and Caption Zoom Methods
No. 1, A Pure CSS Zoom "Kimler Caption no. 1" - (Adding a caption to Stu Nicholls' design)
No. 2, A Pure CSS Zoom "Kimler Caption no.2" - (Adding a caption to Paul Griffin's version) "Original" Photo Zoom
No. 3, A Java/CSS Zoom "Kimler Caption no. 3" - (Adding JavaScript to get what I want)
No. 4, A Pure CSS Zoom "Photo-caption Zoom Version 2" -or- (PZ2) - (Added functionality, Photo-overlay-on-Zoom technique) (Added Oct 2005 - PZ2 "the better Zoom")
No. 5, A Pure CSS Zoom "Photo-caption Zoom Version 3" -or- (PZ3) - (72% Less Code than PZ2, overcomes an IE z-index problem. Photo-overlay-on-Zoom technique) (Added Jul 2006 - PZ3 "the EZ-PZ ZOOM") (Updated 10-Mar-2007)
What do I want?
The answer, of course, is a moving target. Just a few weeks ago, I was happy to find a non-tables, <div>-solution that was XHTML-valid (no zoom). I began my quest because I thought that 400px images were taking up too much page real estate. When I found Dan's image zoom, I became hopeful that I could find a rollover image zoom that was utilized a caption. I didn't. So I made one that incorporated features I deemed important.
Here's a list of important design criteria:
Practical: First and foremost, the method must be easy to use. Adding an image and caption should be done in one spot, with little image editing required & markup accomplished in one file, in one location.
One Image File: I don't want to be bothered to make a large AND small image file and I don't want two images in one file. It takes too much time to do that for every image. I want a thumbnail AND a larger image to come from one file.
Specify either height or width, but not both: If I had a dollar for every time I displayed "properties" or opened an image editing program to see what the height and width of an image is, I'd have enough money saved to send Alex to University (maybe a Private one)! I want to specify one and let the <div> or <img> tags figure out the other dimension. It's a computer - COMPUTE!
Specify the width/height in the HTML: I want to be able to change image sizes on the fly, as I write. I don't want to have to traverse over to another directory, find the correct CSS file, and add ANOTHER width/height set of numbers to the growing list of available image sizes.
XHTML-valid code: I want well-formed pages.
pure-CSS: I don't want a java applet that requires some version of java that readers don't have. We've already got a slide-show viewer that (it seems) half the World can't load. Geez. I take the time to make this stuff, I want people to see it. They don't care about browsers or browser versions (and frankly, I don't want to either, but don't get me STARTED on that topic!)
No tables: I'm off tables. Finished. Finito.
Nice-looking caption that's attached to the photo: I want something that is pleasing to the eye and is easy to modify. (This blogging tool has some nifty code-insertion buttons on the editing page, which I can customize to whatever set of HTML code I want. Ultimately, that's what I've done - program in my final HTML code. Hit one button and several lines of code are added - BINGO. Just need to pick right/left, image file name (most of it's filled out) and type your caption. Simple.
What did I get?
A headache! Trying to bend CSS to your will is like pushing on a balloon: fix one problem, but one pops up somewhere else. "Kimler Caption no.2" (the pure-CSS solution) requires the image width to be specified by the CSS. "Kimler Caption no.3" specifies the width in the HTML, but is not a pure-CSS solution (using JavaScript "onmouse" functions) and has a glitch in FireFox, which is more pronounced when the image is floated right. (See the demonstration page to see if you can spot the problem).
Which method is best?
Added Jul 2006: We're now using PZ3 for our pages, so we consider that "best". It is much easier to use than PZ2 and it fixes a z-index problem with Internet Explorer v6sp2. There's still nothing "wrong" with the "Original" Photo-caption Zoom.
Actually, these blog pages incorporate all three! There is no conflicting code. Run one, two or all three. Each work independently of one another.
The choice is yours.
My answer was different this morning, than it is this evening. While I was writing this blog, I discovered with longer captions, both methods were failing. Fixing the pure-CSS version (no.2) was easy, but fixing the Java/CSS solution (no.3) was its undoing. Trying to marry the 'onmouse' functions with 'a:hover' CSS has been a challenge. Though a fix was obtained (and it works in both MSIE6 and FireFox), there is a visual 'glitch' in FireFox when you exit the image through its base (it's more pronounced when the image is floated to the right).
In the end "Kimler Caption no.2", the pure-CSS version, is best. Initially, I thought the CSS code would be bloated, but by combining selectors, the CSS footprint is reasonable. Once can use multiple class names in the HTML like passing variables to a script. Take a look at the final 'production' code for this version and you'll see what I mean. One can select a RANGE of images widths from within the HTML file (i.e. - 200px to 600px, every 50px), eliminating the need to modify the CSS file. Resizing the image to a multiple of 50px isn't a bother. I normally edit photos anyway (to crop them and reduce their JPG quality to make smaller files). It's a pure-CSS solution that doesn't have ANY visual problems (in MSIE6(sp2) and FireFox(v1) anyway). Feedback on other browsers & versions will be appreciated.
Have a look at each and decide for yourself.
The sticking point.
At the end of the day, the problem comes down to this:
The pure-CSS method does not allow for the specification of the a:hover pseudo classes for the anchor <a> tag within the HTML code (inline). I found a "Syntax Rules" document at the World Wide Web Consortium (W3C) that gave me hope: Syntax of CSS rules in HTML's 'style' attribute. It showed the exact syntax for this situation, but it didn't work. That part of the specification was never implemented.
THe JavaScript method cannot employ 'onmouse' functions on objects it can't actually 'see' (the caption display is set to 'none' & isn't visible to the 'mouse').
However, the pure-CSS version is visually-pleasing, XHTML-valid and easy to use - "Kimler Caption #2". I hope that you find it useful and feedback is appreciated.


















I gave it a very quick look, I know the principles, now I will *try to* implement it in my site.
I'm no programmer, but I can cut-n-paste with the best of them, I would appreciate some idiot guidance notes on what I need to tweek in the code to implement this in the [b2evolution] editor toolbar.
Thanks,
John
I put a trial run on my website as well, I'm interested to see what my readers think
The only difference I'd LOVE to see, and I'm not sure if this is possible, would be if the larger image could just overlay the rest of the webpage while the mouse is over the thumbnail (as in Stu Nichols' solution) rather than push the rest of the content downwards. Or would doing something olike this absolutely REQUIRE two different image files? Just some food for thought...the shifting of the content can be somewhat distracting at times
Anyways, good work!
"On the right is a demonstration of a pure-CSS, XHTML-valid, image & caption zoom. Move the cursor over the image and it will 'zoom' (pop, explode, magnify) to reveal a larger image with a caption."
I got this off of the b2evolution development ma...
I see the code (html, css), but I have no idea on where they should be inserted.
Please help!
I have emailed you privately and will work with you to get it going on your site. How's that for service?
I have played with CSS rollovers, and had a lot of success with them.
Oh, for some reason Safari 1.2.4 doesn't re-draw the text properly AFTER the zoom has gone back to original size. As it works fine in firefox, I blame safari. We'll see what Friday's version of safari does with it.
-Rocketdyke
Thanks for a GREAT feature and of course, the email chat support.
I installed the pure-CSS version ("Kimler Caption no. 2"), I got it running fine, but in order to get the "a:hover" without the underline, I had to add "text-decoration:none;" to the ".Zoom a:hover" selector.
After that, it all worked very good.
Many thanks for your work. Really useful!
Glad you like the pure-CSS photo zoom. Thanks for taking the time to write.
You are correct. Our site (by default) already employs a "text-decoration:none" for links, so it was omitted from the CSS file. I should add it.
-Scott
I want to put the PZ3 into operation where to i paste the code?
AFAIK, the only way of doing that would be with javascript.
I've not looked into it, too much, but could see that it would be a nice (added) functionality.
thanks,
Ankush
LOL ... if only I could get Bill Gates to pay me $1 for every time I had to "tweak" IE ... he'd be a lot poorer and I'd be a LOT richer.
Glad you like it!!
Push the envelope
Great idea going here. Similar in nature to another thingy I built - but your work is way more mature and lightweight. Nice.
Thanks for saying!
I have had a stab or two using pseudo-classes, but was unsatisfied with the results (and disparity with IE).
I've even thought of going with JS to add the "clickage", but am loathe to introduce it.
I am quite intrigued by the page you built for your mate's band. How did you achieve the Band Member roll-overs (the alpha transparency look in IE6?). Neat.
Cheers,
-stk
For the latter, use:
#thisIsAnIeOnlyThing {filter:alpha(opacity=70);}
I slapped together some code loosely based around what you have going here... behind a firewall right now, but will FTP it up tonight at home and re-comment with an example.
Yeah, psuedo classes are lame in IE6. Anchors only. I've even had a:hover not work until I did some crap like {border:1px solid; border:none;} to kick it into gear.
the same thing but with :hover
Wasn't too bad... IE was silly, found an obscure "hidefocus" attribute to make the focus rectangle not rendered.
Cool! Although, there are behavior differences in IE/FFox and Opera.
Oddly, I preferred Opera (click-zoom; release-unZoom).
Firefox has an annoying 'back-to-the-top' scroll, for images part-way down the page.
Both FFox and IE had to click (outside of pic) to unzoom, which I find a tad counter-intuitive (would be better if clicking inside the image, after zoom, would unZoom).
Shows some promise though.
Due to differences between most browsers and IE as far as their take on the various pseudo-classes, I'm thinking that a tad of helper JS might be in order to get every bit of desired functionality.
This is almost exactly where we ended up with our testing, some time ago.
Opera has problems. My mate reports that it doesn't work, with JS disabled, in FFox v1.5.0.7 (though it seems to on my version?)
To pass the litmus test, it needs to:
1) Work with similar behavior across many browsers / platforms (IE6, IE7, FFox, Opera, Safari, & AOL for sure).
2) Degrade gracefully with JS disabled ( or better - work w/out JS
3) Zoomed images must overlay all other elements (overcome the z-index issue in IE) - except windowed elements, of course.
4) Work when pages are served in quirks-mode.
5) Right-floated images open from upper-right, left from upper-left.
I don't want to discourage you. You've got the right idea and have arrived quickly at a high-level 'solution' (tho I'd recommend declaring a doctype and encoding for your page, using "type=javascript" instead of "language=javascript" (which is deprecated) and provide for multiple onload events).
Maybe there's a way? We haven't found one yet and while yours appears close, it hasn't passed the litmus test.
Hope this helps. I look forward to seeing if you can crack this nut!! Keep growing with your web work, you've got real talent!
Bah, can't please everyone =)
Btw, the reason I took such interest in this is because you came up with an idea that uses light code to toggle content in some way *without changing the height of the document* - I hate it when the page jumps when I don't expect it to... "tab boxes" and the like tend to do that across a lot of sites.
Speaking of - it requires javascript to permanently swap the content - but there is a way to make a font-scalable tabbed content box that doesn't change its height when you swap content. Think: hidden-overflow container, children with 100% width and 100% negative right margin (effectively laying them on top of one another), relatively positioned out of the box (invisible), and brought into view by using position:static (thereby ignoring left and top values).
Thanks for the kind words.
Almost forgot, since you seem to be in the CSS-only camp, you might like this - only works in browsers that support adjacent sibling selectors.
CSS-only photo slider - hover over the top thumbnails - drawback is that it requires a LOT of CSS - just a proof of concept
I've been looking for YEARS for a "smart" way to do this.
I finally found my answer on 27-Apr-07. Works like a charm.
Thanks a zagillion!
I've found this gem - Photo Caption Zoom while dreading if I would go forward with creating smaller, larger images and another html page for the larger image and etc.
This tool is easy to be understood and integrated with Wordpress Write Page. Thank you so much for helping a beginner of CSS and XHTML like myself in making PZ3 work on my blog. Your instructions are precise and efficient.
I will promote your product to anyone and anytime.
Thanks a million factorial (1 million!) !
Misty
I have two older tutorials here and here, but the b2evolution version (and file locations) have changed and the PZ code is now at version 3.
The basics are still the same though:
1) Copy the newest CSS into your skin's CSS file (at the bottom).
2) Make a quick-toolbar button that holds the newest XHTML (from same PZ3 page above). The file you need to edit should be in the /plugins folder and called "_quicktags.plugin.php".
3) Modify "_formatting.php" (in the /conf folder) so that all the new tags are allowed. (This page talks about how to do that).
Then you're done.
Give it a whirl and if/when you get stuck, just use our contact form and I'll give you a hand when I have some time.
Cheers
http://stitchtest.000webhost.info/zoom.html
1) The picture is 400px wide (not 479px) - correct that in the PZ31cap SPAN.
2) The shift results from the combination of text-align directives in the #container & #holder DIVs. Remove those and you'll be fine.
3) Also, while PZ3 is free for personal use, a donation is required, when used for commercial purposes.
All three of the Photo-caption Zoom versions utilize a toggle switch (in the class-name) to determine zoom "direction" and float.
Generally, [L]eft-floated images expand down and to the right (into the page) and [R]ight-floated images expand down and to the left (into the page).
(e.g., The first image on this page uses PZ1 -the original version- has a "Cleft" class-name. The 2nd image, which is a PZ3 construct, uses "PZ3-r" classname, where the R = "right")
Check the XHTML notes in the above links.
I hope this answers your question.
Ross
Great code; I'm finding it helpful. Although, for some reason, I'm unable to get the "margin-right: 101%" tweak to work in IE7. Any ideas?
PZ3 in action
Thanks,
Drew
PS - Please have a look at our copyright policy. I'm assuming you're planning a donation?
thank you.
We invented the photo-caption zoom technique - pushing XHTML and CSS a tad past where it was intended. Pretty cool what you can do with plain old HTML and CSS, eh?
A really good place to learn more is with the free w3schools [ XHTML and CSS ] tutorials.
The rest is all practice and play!
There's a tiny image, and when we roll over the mouse on the tiny image, another different large image has change. This is the Amazon sample
PZ3 can be modded to do that AND doesn't depend on javascript. (Have a look at this post, which demonstrates a version that's closer to the Amazon example you provided).
Your codes working great on Mozilla. But I still don't know how to fix the IE issues since I'm a novice on CSS.
Would you please help me which codes should be added to fix the IE issues?
Thanks.
I finally found it...
It's on :
base href="http://randsco.com/blogs/skins/rands/
and
link rel="stylesheet" type="text/css" media="screen" href="rands.css
Thank you STK
I cobbled up a test page and things work as anticipated EXCEPT I can't see a method to get an image to expand left (or right) and UP. Default seems to be DOWN.
Any ideas what I can do?
Thanks
What I want to do is display the mouseover image centered and above the thumbnail by X px.
You can see the problem I am having on the cobbled page http://www.piratesofemerson.com/ship/index1.shtml Since the thumbs are on the bottom of the page, the expanded images can go off the bottom and require a keyboard scroll to get there!
Just use a few on the left.
I think I would like to define absolute coords for the expanded images. Maybe something like you have done with PhotoAlbum - but I don't know how!