May 27
CSS Decorative Gallery
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.
3D Wall Component Giveaways 2008 Design Trends
Comments
Pages: 43 42 41 40 39 38 37 36 35 34 33 … 1 » Show All
There are 422 comments (+Add)
Pages: 43 42 41 40 39 38 37 36 35 34 33 … 1 » Show All


















422 aksoft
February 23rd, 2010 at 8:23 pm
thanks~
421 pascal http://www.nova-media.fr
February 18th, 2010 at 9:30 am
belle realisation en CSS c’est simple et toujours efficace d’embellir des images d’un site .. car trop de jquerry kill mootools
420 Sumon http://www.bangladeshtrades.com
February 13th, 2010 at 2:46 pm
One of the best website of learning CSS design. Thanks for all the tips.
419 Michael http://decorative-frames.googlecode.com/
February 12th, 2010 at 6:47 am
Hi, there!
when you came out with this, quite a time ago, i was really impressed but i realized (as well as also other people commenting here) that you can not use the decorative frames with any other picture sizes than the frame size. so you had to create the frames for every picture size you wanted to use them with, but since i have no idea of PS, i had to think in something else…
now i come back to give you a cross-browser jquery plugin based mainly on the border-image and border-width CSS3 properties where available and the jQuery Border Image Plugin by lrbabe where not.
check it out
and enjoy carnival!
418 Derrick
February 2nd, 2010 at 5:45 pm
Awesome trick!
Is it possible to overlay THREE images? I have three PNG’s with transparency, I’d like to have them overlaid so I can create some neat effects with each individual PNG.
417 nikhil http://designikx.wordpress.com
February 1st, 2010 at 9:39 am
really a gr8 script..now its easy to frame a image. thanx for sharing it !!
416 brenda
January 6th, 2010 at 12:53 am
BrEnDa
415 vincentdresses http://www.hibridal.com
January 5th, 2010 at 11:40 pm
The designs showed here show what simple and tasteful design is all about. Another one to consider
414 Biswa
December 30th, 2009 at 5:16 am
This is one of the best CSS tutorial ever I have seen on NET.I really thankfull to you for this great tutorial.Beacuse you have publish your technique.Really really Great CSS Tips and Tutorial.
413 ThiNg http://www.jellytriangle.com
December 24th, 2009 at 10:41 am
I used this technique to create some fancy image bases checkboxes in a form I am desigining. You can read the full details here on my blog. Thanks for posting this great technique!