Pretty Image Borders with CSS
You may have noticed a lot of the pictures I’ve been posting lately have a little border around them. I started doing this after I saw Raf’s site and realized how easy it is to do with a CSS class.
One of the big annoyances I used to deal with when posting images was that I would always need to add border="0" to the tag to prevent the ugly blue borders that appear when the image is surrounded with a link tag. Although it’s possible, I didn’t even think to disable all image borders in CSS. By why only disable them when we can make pretty borders too?
Here is the CSS I use (place it in your style.css file if you use one):
.photo img, .photo a img {
border:1px solid #CCCCCC !important;
padding:5px;
margin-bottom: 10px;
}
And here is how I use it when I’m writing a post in WordPress (keep in mind that I don’t use the visual editor):
<div class="photo">
<a href="http://blog.raamdev.com">
<img src="http://images.raamdev.com/DSC_1112_640.JPG">
</a>
</div>
And here is an example of the output:
The CSS border adds a touch of style to the image and without it the image border would appear sharp and out of place. Since I added .photo a img to the class definition, even images that are linked to something will appear with the nice border.
There are already buttons for creating links and adding images in the WordPress editor, but adding the
photo button to the editor bar to automatically add the DIV tag with the proper CSS class already specified.

2 Comments, Comment or Ping
Raf
You don’t really need to put the div in there. This is my css class for photos:
.photo{border:1px solid #CCCCCC; padding:5px; display:block; margin:auto;}
However, I do use divs for photos, but it’s only because I want to add captions below the images. This is the css for that.
.photoDiv{text-align:center; margin-bottom:10px;}
.photoDiv img{border:1px solid #CCCCCC; padding:5px; margin-bottom:10px;}
Jan 16th, 2008
Raam
Thanks Raf!
The reason I’m using a div is because when I post a screenshot of something I don’t want the border to show up. I suppose an easier method would be to use a div when I want to remove the border — that way I don’t have to add the div for all the other images I post.
Jan 16th, 2008
Reply to “Pretty Image Borders with CSS”