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.
















Your article’s resource box should help to persuade your readers. No matter how amazing your article is if it’s not succeeding in driving traffic to your website cheap ugg boots
No wonder, with white iphone 4 in your hand will make you be the focus of the crowd! You won’t miss it!
sta buenisima esta pág
I need a well decorate html for my site
vardi butun derslerin gunahi oldum
Another great source for those who wants to see menus, web site trends, galleries, free extension and job for freelancers etc, visit http://www.1artmedia.com, you have online demo and free download. Hope that will be useful for you…
I stumbled on this while googling for some lyrics, I’ll be sure to come back. thanks for sharing.
What talent you have!
I have seen websites where an image(s) has a frame around it and I always wondered how that was done and now I know coming across your website.
Anyways, I’d like to know if this can be done to a rotating banner/jquery/carousel. I don’t understand the difference or the jargon. I need to see examples in action and cut and paste instructions.
Any help, suggestions, ideas, links, books would be greatly appreciated.
Thank you!
(I am a total newbie to website building and design.)
Oops!
forgot to mention that I am talking about the “#5b. Art Gallery – Gold Frame”
Your frames are superb – they remind me a lot of the framed images from http://www.350.com
I need a well decorate html for my site
web sites and nice works thanks
I stumbled on this while googling for some lyrics, I’ll be sure to come back. thanks for sharing.
ea
CSS is a very important part of designing. I must say that you had given a great idea to decorate the image without changing source image.
Florida Web Design
Hi,
nice usage of CSS. I would like to ask you, for your golden frame.
it is possible to upload 2 photos into it rather than just one ?
Your answer to this is greatly appreciated.
Warmest Rdgs,
Chun Wey
Hi, I’ve been playiing around with the HTML & CSS code, but can’t seem to get this to work.
Any advice on what I;ve done wrong would be appreciated !
By the way had to take out the ”
head>
title>
/head>
body>
div class=”photo”>
a href=”#”>
span>
img src=”photo09.jpg” />
/a>
/div>
/body>
/html>
}
body
}
.photo {
margin: 30px;
position: relative;
width: 180px
height: 130px;
}
.photo span {
width: 20px;
height: 18px;
display: block;
position: absolute;
top: -12px;
left: 90px;
background: url(antique_frame1.jpg) no-repeat;
}
Thanks
it’s too important…
Inspires the artist in me. Thanks!
A lot of ways to get artistic online. Thanks for this powerful knowledge.