Posted on 8 September, 2008 By Kim Woodbridge 17 Comments

How to Frame Images in WordPress Posts with CSS

366 • 18 • New frames (by Pragmagraphr)Framing

If you would like to frame the images in your blog posts like the one to the right, all you need to do is add a couple of lines to your CSS file and add the class attribute to your image tags. Don’t worry, don’t worry! I plan to provide step by step instructions.

Once this is set up, all of your images will be framed and padded in the same way, which really helps in making a blog look more professional.

OK – here we go!

**Note – I am using the most current version of WordPress. If you are using 2.3 or lower, some of the settings in the Admin area may be in different locations. Also, please upgrade!! If you need assistance with that, send me an email or a direct message on Twitter and we can discuss. My contact information is in the sidebar to the right.

  1. Go to Design > Theme Editor > styles.css
  2. Copy all of the text in this file and paste it into Word or your preferred text editor. I always back up the original in case I make a mistake or don’t like the changes. The backup allows me to quickly paste the original text back into the file.
  3. Add the following code to your style sheet and save
  4. .left { float:left; }
    .right { float:right; }
    .frame { border: 2px solid #aaa; padding: 10px; }
    img.left { margin: 0 10px 10px 0; }
    img.right { margin: 0 0 10x 10px; }

  5. If you are unable to save and get the message in the screenshot below, you have a permissions issue with your theme files. I am not discussing permissions in this article but feel free to leave a comment or send me an email and I’ll let you know how to fix this.
  6. Now you want to write a new post. Add an image. If you use the visual text editor, switch to the HTML one for the next part.
  7. The following is an example of html code for your image.
  8. <img src="http://www.kimwoodbridge.com/wp-content/uploads/2008/09/
    writable.jpg" alt="Writable" title="writable" width="500" height="31" />
  9. In order to use the css code we added to your style sheet, add the following to the image code.
  10. class=”left frame”

  11. If you want the image placed on the right rather than the left, than simply change the word left in the code to right.
  12. The image code will now look like:
  13. <img src="http://www.kimwoodbridge.com/wp-content/uploads/2008/09/
    writable.jpg" alt="Writable" title="writable" width="500"
    height="31" class="left frame" />
  14. All of your images will have the same frame, if you add this class attribute to the image tag.
  15. You can change the way the frame looks by editing the code that we added to the css file. For example:
  16. .frame { border: 2px solid #aaa; padding: 10px; }
    You can make the frame border bigger or smaller by changing the 2px to a different number. Or you can change the color of the frame be editing the #aaa hex code.

That’s all there is to it. Just add a couple of lines to your style sheet and the class attribute to your image code and you will have professional framed images throughout your site.

photo credit: sveinhal


Related Posts:
  • How to Style the Read More Link in WordPress
  • NextGen Gallery Plugin for a WordPress Portfolio
  • Using Thumbnails for Excerpts Plugin with Query Posts to Make a Custom Sidebar Block in WordPress
  • How to Style a Sticky Post in WordPress 2.7
  • 14 Flickr Plugins for WordPress
  • Posted In : WordPress Tips
    If you enjoyed this post, please subscribe to my RSS Feed

    Post to Twitter   Post to Delicious   Post to StumbleUpon

    17 Responses to “How to Frame Images in WordPress Posts with CSS”

    Trackbacks/Pingbacks
    1. Stuff This in Your RSS - CSS Newbie - 9/9/08 | (Anti) Social Development
    Leave a Comment
    You may use: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .


    Recent Comments

      • Regina Fried: Hi Kim, Yes, I realized I would have to update the file each time WP is upgraded (sigh). It seems like a problem that...
      • Kim Woodbridge: Hi Regina - I have a client on 2.9.2 where the problem just started too - I'm wondering if the webhost changed something...
      • Kim Woodbridge: Hi Keith - Thanks for the info - you have some interesting ideas on how to generate income from a lyrics plugin....
      • Regina Fried: Hi Kim, I'm running WP 2.9.2 on a client's site and just ran into this problem. What do you think of the idea of modi...
      • Keith from shrewdies: Now there's another one (search the WordPress Plugin Database for Happiness Today). Like Hello Dolly, Think Of Happin...
      • Kim Woodbridge: Hi Jake - Thanks for the info. I'm sure there are new themes for video games since I wrote this article a year ago :-)...
      • Kim Woodbridge: Thanks Vered! Some are better than others but it really depends on the materials I'm given to work with....
      • Jake: I found an awesome video game theme for Wordpress, its like nothing you've ever seen before, check it out: ...