Did you like my previous CSS tutorial on how to create gradient text effects? I'm using the same trick to show you how to decorate your images and photo galleries without editing the source images. The trick is very simple. All you need is an extra <span> tag and apply a background image to create the overlaying effect. It is very easy and flexible — see my demos with over 20 styles, from a simple image icon to a rounded corner to a masked layer (both decorative and complex).
What Are The Benefits Of This CSS Trick?
- Saves Time — You don't have to manually create the decorative template in Photoshop and export the individual image.
- Keeps Original Source Images — So you don't have to worry about changing the design theme in the future.
- Very Flexible — You can have a completely different look and feel by just editing the CSS.
- It Works on Any Site — This CSS trick works on any type of site, with any image size.
- Cross-Browser CompatIble — It has passed the test on most browsers (Firefox, Safari, Opera, and even the "buggy IE6").
Basic Concept (see demo)
You need to insert an extra <span> tag within the <div> tag, with which we'll apply a background image to create the overlaying effect. If you don't like to have an empty span tag, you can append the span tag by Javascript (I'll show you how later in this tutorial). Here is how it works:
Then in the CSS, the key point you have to remember is: specify the div element to position:relative and the span element to position:absolute. You can position the span element anywhere you want by using the top and left property.
IE PNG Hack
To make the transparent PNG image work on IE6, I use this wonderful iepngfix.htc hack. Download a copy of iepngfix.htc and insert the following code in between the <head> tag:
<!--[if lt IE 7]>
<style type="text/css">
.photo span { behavior: url(iepngfix.htc); }
</style>
<![endif]-->
Look and Feel
To change the look and feel, simply edit the CSS specifications of the span element. Click the image below to see the demos I have. To show you how flexible it is, I've created 15 different styles (notice the HTML markup is same).
The jQuery Solution (see demo)
I know some of you (particularly the web accessibility fans) don't like to have an empty span tag in the markup. Well, I've solved this issue by using jQuery to append the span tag to the source code. Insert the following code in between the <head> tag:
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//prepend span tag
$(".photo a").prepend("<span></span>");
});
</script>
#1. Simple Gallery (see demo)
Let's take the technique from the previous step and apply it to create a photo gallery.
#1b. Mini Icons (see demo)
This example shows you how to position different icons on top of each photo (note: an extra CSS class name is required in the span tag).
#2. Photo With Text (see demo)
This example shows you how to create a gallery with linking text (em tag).
#2b. Popup Text (see demo)
#3. Mini Paper Clip (see demo)
#4. Cork Board Gallery (see demo, IE6 version)
sIFR Version (Flash Text Replacement) (see sIFR demo)
This example uses sIFR to replace the em text with a handwritten font (notes: in this demo, the span tag is appended by jQuery)
#4b. Cork Board With Masking Tape (see demo, IE6 version)
#5. Art Gallery - Black Frame (see demo)
#5b. Art Gallery - Gold Frame (see demo)
#6. Grungy Watercolor (see demo)
sIFR Version (see sIFR demo)
#7. Glossy Style (see demo)
#8. Wood Panel Gallery (see demo)
Finally, this example demonstrates how you can apply the background image to all elements to create a wood panel gallery: ul, li, and em.
Final Remarks
As you can see, this CSS trick is very flexible. So, be creative! Feel free to incorporate the graphic images and CSS styles in this tutorial to create your own.
















Great Examples!!
Excellent write up!
This technique is exactly what I was looking for and more! Beautifully implemented!
SD
Hi,
I have a question I was wondering if you could help me with. I am using nextGEN gallery and on the demonstration pages of this plugin it shows that examples 1 – 6 are the Idea & Design from Web Designer Wall. I am trying to remove links from my thumbnails and notice in example 5, http://nextgen-gallery.com/templates/example-5/, you have done just that. How did you do it? Did you manage to do it with CSS? I noticed that there is a template=sample5 in the code. Did you create a new template and how? I would really like to figure this out. I posted the question “How to remove thumbnail links” in the nextGEN forum as well as maybe there is something easy I don’t know about.
Thanks in advance.
professional teaching you should pay we for this tutorial
Thank you so much for this tutorial!
I’ve used it here http://www.ninhacozinha.com
Leo
I loved the styles demonstrated here. I’m a beginner with CSS and I just would like to know if I can use any border style for mouseover effect. For example you would put the “brown city” frame as a mouseover effect in one of your examples.
Thanks!
ive been looking online for some css to modify the existing wordpress css for galleries. this post is great but i just don’t know how to get from A to B
Merci beaucoup pour vos idées ! Super travail !
Thanks you
@+
Chantal C
Thanks for sharing, I was just looking for something like this for a website I am designing…
It’s a vevy interesting idea use CSS for decoration pictures.
Thanks.
AMAZING! Thanks for the amazing article, everything I was looking for as a matter of fact!!
I had so much fun here!! keep up the good work!! :)
Fantasic ideas and technical details! Bookmarked!
. Demo
R4
RAVI
cool .. 100 punts tks <3
Is it possible to use this customization with a WordPress gallery ? Which one of my theme .css i need to modify to have this new frames on my gallery?
Thank you :)
Very awesome and pretty great design. I like all of above.
Los Angeles Web Design
la verdad me gustaria aprender muchisimo a hacer este tipo d cosas pero lastimosamente la pagina esta en ingles y no e podido leerla muy bn =( me encantaria q ubiese una pagina como esta en español mi idioma! =)
First out was the iPhone 3G and as you can see the end result is very washed out and a bit grainy but you can choose white iphone 4 instead.