Posted on 8 September, 2008 By 20 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. [sourcecode language='html']Writable[/sourcecode]

  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. [sourcecode language='html']Writable height="31" class="left frame" />[/sourcecode]

  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:

Posted In : WordPress Tips

Did you enjoy this article? I can assist you with your WordPress or Facebook project. Contact me and I will provide you with an estimate. You can also connect with me on Facebook or follow me on Twitter.




web hosting by media temple

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 badge

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.

Recent Comments

    • Victoria12: Wow! This are so cute. It is so much special when our kids do it on their own and give it us as a surprise gift.. So tou...
    • Catherine: I hope that the page owners have a plan for the transition. One concern is that Facebook doesn’t have a great method of ...
    • harm: You no longer can "Add to My Page" This used to be simple, using the facebook UI. Unfortunately facebook removed thi...
    • Phil Derksen: I was referencing plugin #1 in the list btw. :)...
    • Phil Derksen: Thanks for mentioning my Pin It button plugin. I'd love to hear what people think of it and what they'd like to see adde...

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