How To Frame Images With CSS

After seeing that Tyler Ingram recently discussed the idea of creating a simple photo frame in Photoshop, I decided to bring this post to life as it has been sitting in Draft status for quite some time.

The basic idea here is to “dress up” our photos a little bit when posting them on our website or blog. Sometimes a plain photo just looks, well, plain!

Here is an example of a plain photo, which was taken when we went to a Chicago White Sox game earlier this week. It doesn’t look bad, it just looks a little boring. To me, plain photos like this always look like they were just slapped on the page without any further consideration.

Carlos Quentin Home Run 3

Since we don’t want our images to come across as boring, we need to add a little flair (think of the movie Office Space) to make the image “pop” a little bit.

Compare the image above with the following image, which has a small border added around the entire image. While the border isn’t flashy, it does make the image stand out a little more and gives it a nice finishing touch.

Carlos Quentin Home Run 3

The above method is what has typically been used on this blog when adding an image to a post. To create that frame around the image, all we need to do is create a simple CSS class that we will then apply to the image.

1
2
3
4
5
img.imgBox {
	padding: 5px;
	border: 1px solid #AABAC5;
	background-color: #EEE;
	}

To apply the border to the image, we would simply specify the class in our image tag like this:

1
<img class="imgBox" src="..." />

Now, we could stop there and have a nice looking image that has just enough of a frame to make the image stand out.

But that wouldn’t be any fun now, would it?

Using the example that Tyler had shared on his blog, we will kick things up a notch and add a nice black frame around the image and also add a slight white border around the image to give it some separation from the frame. The frame and border will add a really nice touch and look like this when we are done:

Carlos Quentin Home Run 3

Doesn’t that look great?

Tyler created a frame just like this by editing the image in Photoshop, however that means that we need to open each image in Photoshop and manually add the border as part of the image. While it is possible to create an action in Photoshop to streamline this process, it is not very time efficient.

That was when the idea came to me.

Rather than make the frame part of each image in Photoshop, why not make a frame that can be used over and over with the help of a little CSS?

Taking the idea a little further, we can create three or four variations of the frame to accommodate the most common size images that are used within blog posts.

As an example, I have created the following frame that can be used for images that are resized to an approximate size of 500 pixels wide by 335 pixels high. The frame adds 15 pixels to each side and also has included a small notation of my domain at the bottom.

CSS Image Frame

With this pre-made frame image, we can now use a little CSS magic to make that the background image for any image to really make it “pop” on the page.

In order to create this frame around the image, we need to create a new CSS class in our stylesheet that will define the image as a background with a padding of 15 pixels to each side.

1
2
3
4
img.imgPop {
        padding:15px;
        background: url(images/css_image_frame.jpg) no-repeat 0 0;
        }

Then, just like before, we simply need to apply this CSS class to our image tag and we have a beautifully framed image.

1
<img class="imgPop" src="..." />

Obviously this method could be cumbersome if all of the images are different sizes. If that is the case, we could simply slice the frame image up into multiple images and then use CSS to “build” the frame around the image. While this would clearly be the most efficient method, as it would work for any size image, many times the images being used are approximately the same size so a pre-made frame will work well.

Hope you enjoyed this little tutorial and feel free to ask any questions!


del.icio.us Digg Netscape StumbleUpon Technorati


RSS feed| Trackback URI

27 Comments»

Comment by Kelvin Kao from Puppet Kaos
2008-07-25 18:03:11
MyAvatars 0.2

Um… pretty cool trick. Might want to add a reminder for your RSS readers though. I was like… hm… the two pictures look the same, then I thought, duh, I need the CSS file.

Comment by derek
2008-07-25 19:30:23
MyAvatars 0.2

Doh, I didn’t even think of that aspect of it. Sorry about that.

 
Comment by Nick from romandock dot com
2008-07-25 20:12:21
MyAvatars 0.2

I thought the same thing and then realized I would need to actually click through to the article :S

Nicks last blog post..Randy Pausch Has Passed Away

 
Comment by Michael Kwan
2008-07-26 17:12:07
MyAvatars 0.2

I was just about to say the same thing. I was reading the post in Google Reader and all the images looked the same.

Michael Kwans last blog post..More Movies for the Weekend

 
 
Comment by life coach
2008-07-25 19:29:16
MyAvatars 0.2

Super useful…thanks!! i will definitely make use of this CSS.

life coachs last blog post..Success in Business Coach Training

Comment by derek
2008-07-25 19:30:58
MyAvatars 0.2

Great, I am happy to hear that you found it useful.

 
 
Comment by Nick from romandock dot com
2008-07-25 20:11:46
MyAvatars 0.2

That’s pretty cool…for now though, I think I might just continue to slap them on there…certainly something to keep in mind though, especially for my Sunday Snapshots!

Nicks last blog post..Randy Pausch Has Passed Away

 
Comment by Andrea
2008-07-25 21:32:41
MyAvatars 0.2

very informative post. although I am not for bordering pictures when I post them online. but i will say that Tyler’s picture of the seagull looks really great. I in no way mean that *yours* isnt great, im just not a huge fan of baseball. What I like about your picture is the crispness and quality of the picture. Ive been wanting a Nikon D40 (like yours) for the longest time….

Comment by derek
2008-07-26 01:49:17
MyAvatars 0.2

You don’t need to rationalize why you don’t like my picture, I can take it. ;)

Oddly enough, taking the camera to the baseball game is the first time that I have really used the camera much away from home. I’d love to develop my photography skills but often just don’t have the time.

Comment by Nick from romandock dot com
2008-07-29 12:05:30
MyAvatars 0.2

The problem I find with a nice camera like that is that there is the fear of breakage or loss as well as the fact that it’s not as easy to haul around as a smaller point-and-shoot model.

Nicks last blog post..Randy Pausch Has Passed Away

Comment by Andrea
2008-07-31 20:28:44
MyAvatars 0.2

the nikon d40 advertises to be nikon’s smallest digital slr. that is the main reason why i find it so attractive. my coworker bought it after i told him that was the camera i was wanting! :p

my kids make me hesitant to want to invest in a quality camera just for the fact that I am sure it will be expensive to fix/replace as things just “accidentally” break when they touch things.

(Comments wont nest below this level)
 
 
 
 
Comment by Ling from Uptake Subscribed to comments via email
2008-07-25 22:29:18
MyAvatars 0.2

Oh! First I thought you were going to ‘doctor’ the image. The frame does spice up the image nicely, though.

 
Comment by Tyler Ingram
2008-07-25 23:05:18
MyAvatars 0.2

Heya Derek! Cool thanks for bringing this post back! I will have to work in implementing it into my blog, though the first example is the easiest, getting it to work though with a varied height image might be tricky. Currently all my photos have a max width of 500px. Off to the drawing board!

Tyler Ingrams last blog post..Simple Framing Of Photos In Photoshop

Comment by derek
2008-07-26 01:50:33
MyAvatars 0.2

Let me know how it goes!

 
Comment by Tyler Ingram
2008-07-29 17:45:11
MyAvatars 0.2

Will do though I’ll have to check back with you next week. Unless you come up with something first

Tyler Ingrams last blog post..The Secret In Making Money Online Made Me Lots Of Money!

 
 
Comment by Jayson
2008-07-26 01:29:39
MyAvatars 0.2

That’s a pretty nifty little trick - I think I’ll try and do it on our site. Thanks for the idea

Comment by derek
2008-07-26 01:51:31
MyAvatars 0.2

Thanks, I am glad that you like it. Hopefully you can use it on your site, let me know if you have any questions about implementing it or need any help.

 
 
Comment by Fred from High Interest Savings Accounts
2008-07-26 06:44:01
MyAvatars 0.2

This was a great post. I love these practical CSS and HTML tutorials. Thanks Derek.

 
Comment by Nicole Price
2008-07-26 08:47:22
MyAvatars 0.2

I suppose that you need to be fussy. I am just one of those aim and shoot photographers and rarely if ever use photos in my blog. I found this a bit too technical for me!

Nicole Prices last blog post..Green Gifts

Comment by Andrea
2008-07-26 21:28:33
MyAvatars 0.2

I agree that it was a bit too technical. my eyes just sorta glazed over as i read this. :p

 
 
Comment by Nicole Price
2008-07-26 08:49:52
MyAvatars 0.2

Sorry Derek, if you visit my blog you will know what I mean. The quality of the photographs that I do publish are in no way comparable to what you have done here. That is what I mean.

 
Comment by Larry from Commercial Lighting
2008-07-26 09:13:20
MyAvatars 0.2

Cool trick. I especially like that frame

 
Comment by pauletet
2008-07-26 21:14:30
MyAvatars 0.2

Thanks for the info.

 
Comment by Justin from Airsoft Guns
2008-07-27 09:37:56
MyAvatars 0.2

I never thought about that… images really do look better with frames. I will surely have to utilize that tip. I’ll probably just use the simple border, as that looks good enough.

 
Comment by Steve from Free iPods Subscribed to comments via email
2008-07-28 15:14:57
MyAvatars 0.2

I wondered where you were going with the first image (border was uninspiring to my mind) but the black border does make a huge difference.

 
Comment by yarn
2008-07-29 01:04:08
MyAvatars 0.2

really thanks a lot for this great post.
regards

 
Comment by Jaxson from Tool Belt
2008-08-01 10:28:02
MyAvatars 0.2

I have a website with products that this will look really good on. Thanks.

Sorry about not using keywordluv earlier.

 

2 Trackbacks / Pingbacks

 
 
Note: This site uses KeywordLuv. Enter YourName@YourKeywords in the Name field to take advantage. Keyword only entries will have the link removed.

Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line=""> in your comment.