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.
















Many thanks for the tutorial !
I have found one problem I can’t seem to resolve and any advice would be greatly appreciated.
I have notice I can only get the code to work/display correctly if the image files I use have block security within the properties. If i unblock the security restriction then the images do not display within the gallery ! I have looked at forums to find a solution for this but have to date been able to find one that works.
Inspires the artist in me. Thanks!
Another questionnaire, the participants’ problem identification and structuring, idea generation, problem elaboration and clarification, such as creativity, problem solving insertion sezkin idea which one’s preferred styles are evaluated. While participants preferred the style of non-disclosure and intellectual development of ADHD, with ADHD, participants chose to produce ideas.
How would you apply this on NextGen wordpress gallery? I can see this demos but no explanation about the way to do it:
http://nextgen-gallery.com/templates/example-1/
Any tip will be welcome.
Thank you for sharing all of your marvelous tricks! Do do beautiful work!
Great tutorial – I’ve used it as basic image protection on my partners website, a transparent png overlay. Preferable to disabling right click.
A lot of thanks ^^!!!… I’m moving my website to a new host, then I’m improving some features, and this tricks are very very beauty and useful n_n…
Is a program that can design a variety of styles, very interesting.
I’m curious if you can apply these styles to NextGen Gallery ALBUMS. I’ve seen plenty of styles applied to galleries, but it’s tough to see any for styling the albums themselves. Thanks!
@Rich –
It is possible. I know the NextGen Gallery site mentions but doesn’t have any description on how to do it. You have to download the static HTML examples from this site then follow the directions to create the template file for NextGen gallery in your site’s theme folder (http://nextgen-gallery.com/templates/). This is a PHP file. You will have to copy the elements over from the example you wish to use and do some code editing. I created gallery-template.php file in the directory mentioned above, I also put the image file and css in that folder too. Don’t forget to call the gallery and include the template you wish to use with the short code: [ nggallery id=1 template=sample1 ]
Hi I am still learning php,css. can you share the template code so we can get an idea…
Agreeing with Neel…. I would love to see a sample of how you coded it to call on your styling! Thanks!
This awesome! Very like it – thank you!
Is a program that can design a variety of styles, very interesting.
Hey just wanted to give you a quick heads up. The text in your post seem to be running off the screen in Internet explorer. I’m not sure if this is a format issue or something to do with web browser compatibility but I figured I’d post to let you know. The layout look great though! Hope you get the issue resolved soon. Thanks
Quite nice! Thanks, I’ll try to use this on one of my sites. It makes any gallery to look fresh and fun.
And then he handed you the thirty-five 45
Fantastic, thanks so much
thanks, very goods jobs
[...] CSS Decorative Gallery [...]
Fantastic web site!! Thank you so much!
You are the MAN! Thanks again for the great tutorial and tips. I have followed you about 4 years now and you’re really talent…
i ever try this tutorial it’s very great but i have problem when use a gradient, gradient didn’t work..could you help me