Skip to the content...

Welcome to the David Walsh Blog. I'm a MooTools, Dojo, jQuery, CSS, and PHP Web Developer located in Madison, Wisconsin, United States. Please contact me if I can make your experience on my website better.

Create a Double Border Image Effect Using CSS

16 Responses »

CSS doesn't allow for too many cross-browser compatible effects. Webkit has added some webkit- CSS effects, but I'm talking about a more toned-down, subtle effect. Did you know you can add a double-border effect to your images using basic, cross-browser CSS? Let me show you how.

The CSS

img.double-border { border:1px solid #ccc; padding:2px; background:#eee; }

You can give your image a background-color property and add padding to the image to create the double border effect. It's a simple but effective design trick. You could enhance an image's appearance during the hover effect using this "double border."

What would you use this for?

Discussion

  1. October 15, 2008 @ 8:52 am

    Nice effect, David! Also I like the MooTools logo on Sam’s hat.

  2. October 15, 2008 @ 9:57 am

    Yes, this is a nice way of acomplishing that effect, i use it very often just with a larger padding. On one gallery i used white background, grayish border, 5px padding and then an aditional drop shadow effect (image). So the final result turns out to be perfect.

  3. October 15, 2008 @ 10:11 am

    I can think of a couple of browsers that do not support this and I ain’t gonna say they are both made by MS ;)

  4. October 15, 2008 @ 10:20 am

    Can you be more specific with that ?

    I tested my way in most of the browsers (IE6, 7, FF2, 3, Opera, Safari etc.) and works like a charm. Only problem i can think of (would need to test that) is maybe the default img display:inline;

  5. catar4x
    October 15, 2008 @ 10:49 am

    I know this tip by css-globe 6 months ago.
    Use a black border and white background to have a nice effect.

  6. ahmed
    October 15, 2008 @ 3:15 pm

    Very slick!

  7. October 15, 2008 @ 4:11 pm

    That is pretty nice. Never would have thought of using background and padding to create the inner grey “double” border.

  8. October 16, 2008 @ 7:35 am
  9. October 16, 2008 @ 9:17 am

    @Elmas — it’s all about the right !DCOTYPE. If you manage to run IE 6 in standads mode — you will see the padding. If you do not manage, however, you will run the page in Quirks mode and not see the padding.

    The easiest way to trigger Quirks mode is to add a XML prologue or add anything but white space before the DOCTYPE e.g. comment ;)

    See at http://en.wikipedia.org/wiki/Quirks_mode for quick info.

  10. October 16, 2008 @ 10:31 am

    Really cool, simple, elegant idea. Nice work.

  11. October 16, 2008 @ 5:27 pm

    You can also use

    outline: 1px solid #000;

    to achieve the same effect.

    // Tim

  12. Иван
    October 18, 2008 @ 7:35 pm

    Outline is not cross-browser ;)

  13. October 20, 2008 @ 1:32 am

    Thanks for sharing this

  14. jose
    October 20, 2008 @ 7:17 am

    He intentado crearlo en la web http://www.eyaculacion-precoz.info pero no he podido, me puedes ayudar?

Be Heard!

Share your thoughts with fellow developers of all skill levels! I want to hear from you!

Name*:
Email*:
Website:  
Wrap your code with <code> tags, f00!