5ThirtyOne

Derek Punsalan

Media Temple

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.

Backblaze unlimited secure online backups Find out what Backblaze can do for your online backups

22 Comments • RSS

  1. Ronny says:

    Thanks! very nice and simple gallery

  2. Delena says:

    This didn’t work for me but then I’m a newbie to CSS. I must be doing something wrong. What do I put in place of “#tb” where it say “href=#tb”?
    I think that’s what’s missing. Would that be the path to the thumb image including the url?

    Looks like this would work great for me if I could figure.

Leave a Reply

Comments may be held for moderation. If your comment does not appear immediately, do not repost. I reserve the right to remove any inappropriate or off-topic comments. If you plan on sharing helpful code, please pass it through Postable first. Want other to know who you are? Register a Gravatar.

Syndicate

Subscribe via RSS or Email

Advertisements

9rules network

5THIRTYONE

Public projects

Select project

Something new

Fresh content

Show Latest

Google, the noun that became a verbGoogle. Openly embracing and sharing your info with the online giant... Or trying your best to keep your data hidden from Vader? After you watch the clip, check out this infographic of ... Link