Posted on 8 September, 2008 By Kim Woodbridge 20 Comments

How to Frame Images in WordPress Posts with CSS

 
Share

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
  • Converting a Static Website to WordPress: Mary Shelley and Frankenstein Part 2
  • Posted In : WordPress Tips
    If you enjoyed this post, please subscribe to my RSS Feed. You can also connect with my Facebook page or follow me on Twitter.



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

    CommentLuv Enabled

    Recent Comments

      • Ari Herzog: Agreed on the updates/inbox snafu. I rarely see page updates and I know where they are! .-= Ari Herzog´s last blog .....
      • jayson: Kim, Love the themes. I am looking to update the theme on my site to something more appropriate. My site is all abou...
      • vered: "I wish more people would use this. I think it’s silly when I get updates for things occuring in Kansas and California –...
      • Dennis Edell @ Direct Sales Marketing: I was speaking generally, not specifically this month. how exactly do you work things? .-= Dennis Edell @ Direct Sales M...
      • Lucy Beer: Unfortunately I think next to no-one actually sees those "Updates". They're buried in a subsection of the inbox and I do...
      • Kim Woodbridge: Hi Marbella - Thanks! I had a great time....
      • Kim Woodbridge: Hi Julie - I'll probably try kayaking again next summer but I don't know if I will become much of a kayaker - I had a di...
      • Kim Woodbridge: Hi Vered - If you ever get the chance, you should go. It's like a different world - it's so quiet and peaceful....

    About

    Kim Woodbridge is an accomplished Information and Technical Consultant specializing in the entire implementation of a WordPress based website including installation, theme design, upgrades, unique customizations and ongoing site maintenance.

    Wordpress Services

    • Installation, upgrades and maintenance
    • Conversion of existing html and css templates
    • Theme and plugin recommendations
    • CSS customizations
    • Troubleshooting and tweaks for unique situations
    • Customization for individual blogging goals and needs
    • Training and advice