May 27

Tagged in: , Comments:Add

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).

View Demo Gallery

Download Demo ZIP

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:

Basic Concept

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).

Demo screenshot

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.

Demo 1

#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).

Demo 1b

#2. Photo With Text (see demo)

This example shows you how to create a gallery with linking text (em tag).

photo with text

#2b. Popup Text (see demo)

popup text

#3. Mini Paper Clip (see demo)

Mini paper clip demo

#4. Cork Board Gallery (see demo, IE6 version)

cork board gallery

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)

sIFR demo

#4b. Cork Board With Masking Tape (see demo, IE6 version)

Demo 2b

#5. Art Gallery - Black Frame (see demo)

black picture frame

#5b. Art Gallery - Gold Frame (see demo)

gold art frame

#6. Grungy Watercolor (see demo)

grungy watercolor

sIFR Version (see sIFR demo)

sIFR demo

#7. Glossy Style (see demo)

glossy style

#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.

wood panel

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.

Delicious Stumbleupon Digg

3D Wall Component Giveaways 2008 Design Trends

Comments

Pages: 33 32 31 30 29 28 27 26 25 24 231 » Show All

There are 323 comments (+Add)

  • 323 chuhe

    good good, very nice, thanks….

  • 322 Ahmad Esmaeilzadeh http://shomalgan.com

    I used it with my design,
    here : http://www.shomalgan.com/blog/2008/12/11/portfolio-page-and-nextgen-gallery/

  • 321 albertto

    Awesome !!! Thanks for share.
    if(woman){
    write “I love you”
    }else{
    write “best regards”
    }
    :)

  • 320 Markus

    Can somebody post a good way to get the black brush-border for all sizes?

    I had a try, but im not sure, if this way is really ok. I took the background-image from the span and placed it as a real img in the span. I adapt the brush-border image size and the padding to the image size automatically by PHP so that it fits.

  • 319 publicitate online http://www.promovare-site.net

    Very nice work, good job!

  • 318 st.killian http://plurk.com/killianklls

    so cool !!

  • 317 Mellick

    This is Brilliant, I have been looking for something like this for ages for my members site. I have one problem with it for use on my site, maybe someone can suggest a fix. I want to use it to display user thumbnails which are all the same width of 130px which is no problem but they are not all the same height. I would like to set the image frame to display the top 100px of the image but clip anything below that as this peaks out from behind the frame. I don’t want to set image height as this will distort the images. I have tried setting the css for li to a height of 100 with overflow hidden but this cuts off the bottom of the frame. A few other things I have tried have been just as unsuccessful.

    Anyone got any suggestions?

    BTW I stumbled upon this site by accident and just love it

  • 316 mike

    Can you provide the full php file for the templates. I am not getting how to make them at all.

    Thanks!

  • 315 bebo music skins http://www.wantaskin.com

    great stuff, ive been looking how to do this for ages, thanks

  • 314 Herramientas blog http://maestrosdelblog.com.ar

    cool job, very cool job people

Pages: 33 32 31 30 29 28 27 26 25 24 231 » Show All

Post Your Comments

(required)

(required)

Comment Guidelines

  • Please keep comments related to topic. And be nice, don't spam!
  • Basic HTML tags are allowed:
    <a href> <abbr> <acronym> <blockquote> <code> <em> <strike> <strong>
  • Note: un-related or spam comments will be deleted.

Live Comment Preview

Advertise Here
advertisement

Back to top