What's with all the pink?

Find out more at Pink for October or get your own Pink!

5ThirtyOne

Avatar

A blog. A website. A semi-coherent receptacle for Derek Punsalan mixed with excerpts of technology, personal interests, and noteworthy items.

Twitter: Saigon nightlife... inter-est-ing. Squared, Lush, and Gossip.
Get content delivered: RSS | Email

Derek Punsalan...is Sylvia Loh MyQuire - Get stuff done with people who share your passions Box.net - Access your files anywhere with Box

Current » This post published on August 6th 2006 at 1:06 am

Javascript-free image gallery

5thirtyone image gallery portfolio

After having grown tiresome of the flash solution which I had made use of for quick gallery previews in the portfolio, I decided to return to the basics with a CSS based image gallery. Plain-vanilla CSS using relative & absolute positioning to achieve a clean scriptless gallery.

For the following tutorial, we’ll construct a simple two image model using two thumbnail images, and their respective full image previews:

<div id="image_gallery">
<ul id="gallery_thumbs">
<li><a class="thumb" href="#tb"><img src="/img/thmb.gif" alt="thmb" /><span><img src="/img/lrg1.gif" alt="prvw" /></span></a></li>
<li><a class="thumb" href="#tb"><img src="/img/thmb.gif" alt="thmb" /><span><img src="/img/lrg2.gif" alt="prvw" /></span></a></li>
</ul>
</div>

Using the above structure, we now have a gallery container designated by #image_gallery, and a basic unordered list with the thumbnails and associated full previews wrapped with <span> tags to hide using CSS.

#image_gallery {
position: relative;
overflow: hidden;
}
ul#gallery_thumbs {
list-style: none;
margin: 0;
padding: 0;
}
#gallery_thumbs li {
background: none;
display: inline;
}
.thumb img { /* styles thumbnail previews */
background: #fff;
padding: 2px;
border: 1px solid #ddd;
}
.thumb:hover img {
background-color: transparent;
}
.thumb span { /* hides large previews */
visibility: hidden;
position: absolute;
}
.thumb span img { /* styles large previews */
background: #fff;
padding: 2px;
border: 1px solid #ddd;
}
.thumb:hover span { /* displays preview while hovering over thumb */
visibility: visible;
top: 80px; /* absolute positioning to control where previews are displayed */
left: 0;
z-index: 100;
}

Now that we have the basic HTML & CSS, we can now experiment with styling a gallery to match.


Explore » Discover new content on 5thirtyone.com

This post tagged , . Explore similarly tagged content below or visit a random entry. Visit the archives for additional content.

Meta » Gritty post related bits

The post titled Javascript-free image gallery is categorized under Noteworthy. Feel free to leave a comment or trackback from your own site.

Advertisement

Reader Activity: Have something to say about Javascript-free image gallery?
19 Comments
  1. Am I the only person that isn’t working for? The folio section is displaying both the thumbnail and the picture, and I’m using Firefox in OSX …

  2. Super stuff. Need to test this asap.

  3. Am I the only person that isn’t working for? The folio section is displaying both the thumbnail and the picture, and I’m using Firefox in OSX …

    That’s strange. Looks to be OK on my end with Firefix 1.5, Safari 2, Opera 9 (somewhat buggy displaying other images with the smallest mouse gesture), and IE 7 (IE 6 will be updated via software updates - does not understand the thumb:hover). I just hope I write the tutorial to match the actual gallery ;) Comment back and let me know what version you’re using.

  4. IE6 users could add a separate class, such as “.spanHover”. Then add the following to each span:

    onMouseOver=”javascript:this.className=’spanHover’;”

    Kinda defeats the purpose of doing without javascript, I know. But, it’s an easy fix for IE6 users.

  5. Simple fix. We all know that the time is near that Windows users the world over will begin using IE 7 thanks to the high priority update that will go out through Windows Software Updater. Oh what a happy week that will be as sites show their IE 7 faults.

  6. IE6 will be around for a while in the corporate space (sadly) however most users of XP will have IE7 thrust upon them as an update (as Derek mentions).

    IE7 has been around for quite some time now in the various builds that have either leaked or been made public, however I’m sure a large number of folks are going to get caught out with non IE7 friendly sites. :)

    A more important note, I believe you’ve found a simple yet elegant way of using CSS to make a basic gallery. The greatest thing? No javascript, so it will work in virtually anything. :)

  7. Wow, sweet stuff, this is going to be useful for my portfolio (when I get one…).

  8. I haven’t visited your site in a while but just noticed this article. I actually made something quite similar on my myspace account a few months back. Its on my blog page which I covered up and placed a photo gallery on. You can find it here.

    I actually was inspired to create it after I downloaded your lime green overlay a while back. Thanks for planting seeds of inspiration :)

  9. So…I guess what I’m getting at is what do you think about it?

  10. Looks good. Reminds me of my two year tenure at Washington State. Good times for sure.

  11. hi there

    love your template, will modify and update soon

    just a bug

    .thumb:hover span { /* displays preview while hovering over thumb */
    visibility: visible;
    top: 80xp; /* absolute positioning to control where previews are displayed */
    left: 0;
    z-index: 100;
    }

    top: 80xp; should be
    top: 80px;

    :) was goin mad.

    and is this script dependant on the size of the images? somehow we could’nt get it working

  12. Fixed that little typo. And for the record, there are not scripts involved. As far as I know, size does not effect whether or not the larger preview is shown. I managed to display 450px wide large images when the thumb was hovered over.

  13. geez that was fast :) appreciated

    however there’s something working improper with what i have been trying..
    http://www.braininpain.com/blog/html/gallery.html

    i ain’t a coder yb the way, just designer developing my coding skills…

    is there an actual working example on this menu? any url?

    thanks in advance.

  14. It looks to be working ok with the first image having a larger preview on rollover. You mis-linked your second rollover image.

  15. hmm
    why it happens to be not working here i wonder.

    firefox 2.0.0.2 with a ppc emac(runnin 10.4.8)
    and just asked for a pc user to check too..says don’t work

    any suggestions?

    (sorry to interrupt and thanks alot for your help and effort)

    ¿ : /

  16. Jim

    Am I going blind? I can’t see the live example anywhere…

  17. aaa

    could this be used on myspace

  18. There is no Javascript so I don’t see why something like this couldn’t be used on MySpace.

  19. I think this is cool but I sure hope there’s a demo page where we can view how it works. :)

Leave a Reply

Your comment may be held for moderation. If your comment is not displayed immediately, do not repost. I reserve the right to remove any and all comments deemed as personal attacks or completely off-topic. Please use the appropriate discussions forum if your comment is not applicable to the current article.

Archived: Browse previous activity by category
Browse an overview of recent activity

View Tutorials » Step-by-step go make something tutorials

WordPress Custom Fields; laying text over your lead graphic

For WordPress users, there are certain scenarios when the typical reverse chronological presentation of content is just not enough. I have experimented with different methods ...

Remove DRM protection from iTunes tracks with iMovie HD

A few days back I found myself perusing the iTunes Music Store looking for a few songs that I had heard via Sirius*. After completing ...

View Apple » Apple software & hardware related articles

"What you’ll find in my Leopard"… and what you won’t

I had made plans for a proper break-down concerning the features, changes, and updates for Apple's latest feline incarnation - 10.5 Leopard. Ultimately, I decided ...

How-to: Proper Gmail IMAP for iPhone & Apple Mail

UPDATE 11/18: inaequitas reminds us that in order to star messages on your iPhone, simply move the message the starred items directory. UPDATE 10/26: RayL re-confirms ...

View Personal » Personal thoughts & rants

Planning on carrying the momentum, 2007 to 2008

Syl caught a photo of Boo (Mini Rat Terrier) in a rare "not bouncing off the wall and couch" mode The later part of 2007 was ...

November is purple, Pancreatic Cancer Awareness

Educate and promote awareness Last month 5ThirtyOne went pink to support Pink for October raising awareness for Breast Cancer Awareness Month. A co-workers partner raised the ...

View Inspiration » Design related announcements & articles

Lovely Blogs highlights "blog design"

Ben Bleikamp, also known for his entrepreneurship blog College Startup, has been hard at work coding and compiling his design community share Lovely Blogs. Now ...

Rebooted - “Fat” faux footers

Inspired by Phu's Many colours of a reboot, I've decided to share my favorite sites which utilize "fat" footers. I think the more appropriate title ...

View Mobile » Mobile technology & information

Asus Eee PC sub-notebook running Apple OS X

Ignoring the legalities or hair pulling from Apple's legal department, Dan decided that it was high time for a sub-notebook running OS X. If Apple ...

Unlimited SMS savings for iPhone (or any phone) family account holders

There are currently three different iPhone plan add-ons for at&t family accounts. Each plan offers unlimited data usage & visual voicemail. The only difference which ...

View Noteworthy » Take note, noteworthy posts or news

Maybe shopping in person actually does save time?

Yesterday I was hoping to have some free time to visit the grocery store to pick-up a few necessities. Unfortunately, I realized all too late ...

Warning! Gmail users beware, fake upgrade emails

UPDATE: According to a comment on digg, gmailupgrades.com has been taken down. Important FYI update for any Gmail users. If you receive the following email in ...

View Productivity » Staying productive, articles pertaining to productivity

Box.net evolves, say hello to OpenBox

Box, a long-time favorite mentioned in Box.net as a collaborative file manager, has evolved into OpenBox adding new features which would tie the service into ...

Basecamp, activeCollab, and Goplan compared

UPDATE 11/18: activeCollab is no longer offered as a free project management collaboration download. From the design, development, and product strategy company Webreakstuff comes a new ...

View WordPress » Articles pertaining to the rock solid CMS WordPress

The Unstandard WordPress theme

The Unstandard WordPress theme is released / shared with the intent of breaking the typical blog mold. Farewell to the blase reverse chronological text heavy ...

WordPress 2.3+ official support for custom database error page

Some time ago a tutorial was posted on 5ThirtyOne which addressed customizing the DB Error page rendered whenever visitors landed on heavily trafficked WordPress site. ...

Advertisement



External: Your reader says "feed me"
Finished? Return to the top

Flickr » Subscribe to my Flickr

  • Coconut juice
  • Dried fish
  • Fresh crabs
  • Fresh frogs
  • Rooftops
  • Vietnam Airlines