Adding borders and shadows to images in WordPress

I recently posted about classes you could use in TTG text blocks to place and style images. Two of those classes are “border” and “shadow.”

edit-imageThis post is about adding borders and shadows to images in WordPress. And it’s really as simple as adding one or two words to the Image Details dialog box. In the WordPress post editor, once you’ve added an image to your blog post, click on on it. You’ll see a small box with some icons pop up. Click on the pencil icon.

This will take you to the Image Details page for that image. If the Advanced Options aren’t already showing, click on the down arrow next to Advanced Options. One of the advanced options is “Image CSS Class”. And here is where you can apply the border and shadow classes, or any other classes for that matter. Just type them in, using a space to separate classes.

Just add class names to the Image CSS Class field.
Just add class names to the CSS field.

And that’s it. Update the image, update the post, and take a look at the post preview or, if you’ve already published the post, the actual post. Be sure to refresh your browser. The image above has both the border and shadow classes applied.

But there’s one little snag you might run into. And that’s if you’ve added a caption to the image. When that happens, the class .wp-caption gets added to the div that contains the image tag. And the class .wp-caption just happens to have a rule that essentially eliminates the border around the image. And because of a thing in css called “specificity”, the .wp-caption styling overrides the styling for the image element by itself. You see, the more specific the css selector, the higher priority it takes. CSS classes are more specific than html elements (the IMG tag in this case) so the class takes priority.

But there’s a fix. There always seems to be a fix. In this case, the fix is to write a css rule that’s even more specific than the one being applied:

.wp-caption img.border {
border:1px solid black;
}

What this does is to apply a border to an image element that is inside of something (a div in this case) that has the wp-caption class applied. Now that’s pretty specific and it overrides the straight .wp-caption rule and restores the border to the images.

Just add that code to your custom css file.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About this site

This site is: a repository of time-savers and best practices from a user's perspective, picked up from several years of using TTG plugins.
This site is not: a support site.
Read more here.

Subscribe to new posts

Tip Jar

If this site has saved you some time, kept your hair attached, or otherwise prevented you from tossing the mouse through the monitor, feel free to donate.

Categories


Highly recommended. This is my go-to Lightroom book. Click on the book image. (affiliate link)

Affiliate link!

Current TTG versions

Backlight  4 & 5

See the Backlight Modules page on your site for latest Backlight and module versions and changelogs.

You’ll also find the latest version number and download link for the Lightroom Publisher plugin.
(BL 3 and later)

 

Backlight 1 Versions

Backlight 1.2.4
Pages module 1.2.4
Cart Add-on 4.1.7
Client Response Add-on 7.1.3
Theater Add-on 1.2.6
Galleria Add-on 1.0.0
WordPress Add-on 1.2.6
Publisher 3.2.3

Backlight 1 has seen its end of life. See this post.

CE4 Versions

note: CE4 is no longer being developed or sold. See this post.

TTG-BE: 2.0.5a
Autoindex: 7.0.8
Cart: 3.1.4a
CRG: 6.1.3a
Gallery: 6.1.10
Pages: 7.0.15
Publisher: 2.3.3
Stage: 6.1.6
Theme for WordPress: 3.1.2