WordPress Image Caption CSS 19

Posted by Trey Connell on January 24, 2009

If you use anything other than the default WordPress theme, you’ve probably noticed that image captions look different in TinyMCE than they do on your site. This is because many themes do not include the styles associated by WordPress with the images you insert into your posts.

In order to get the styles to show up, simply paste the CSS below into your theme’s css file (style.css).  That will get your default styles working, and you can customize from there.

/* Captions */
.aligncenter,
div.aligncenter {
	display: block;
	margin-left: auto;
	margin-right: auto;
}

.wp-caption {
	border: 1px solid #ddd;
	text-align: center;
	background-color: #f3f3f3;
	padding-top: 4px;
	margin: 10px;
	-moz-border-radius: 3px;
	-khtml-border-radius: 3px;
	-webkit-border-radius: 3px;
	border-radius: 3px;
}

.wp-caption img {
	margin: 0;
	padding: 0;
	border: 0 none;
}

.wp-caption p.wp-caption-text {
	font-size: 11px;
	line-height: 17px;
	padding: 0 4px 5px;
	margin: 0;
}
/* End captions */
Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. GG Tue, 14 Apr 2009 15:32:04 UTC

    Thanks for this. I was having a devil of a time trying to make captions look right!

    GG’s last blog post..Missionary Dating

  2. Brian Jarrett Wed, 22 Jul 2009 10:44:48 UTC

    Fantastic post! I’ve been trying to fix my image captions for some time. This was perfect.

  3. [...] finally got image captions working properly for my custom WordPress theme.  I found the CSS here and I’ve included it below for [...]

  4. Robert McIntosh Thu, 30 Jul 2009 12:01:39 UTC

    thank you!

    I’ve been struggling with this for ages. What a marvelous help

  5. Christoph Jochum Thu, 06 Aug 2009 15:26:38 UTC

    Great!!!
    I´ve been messing with this for days without success.
    Thank you

  6. otholate Sat, 17 Oct 2009 09:06:38 UTC

    thanks a lotfor this. works like a charm.

  7. Grace Sica Thu, 05 Nov 2009 20:00:58 UTC

    Awesome! Thank you!!!!

  8. El desalmado Mon, 16 Nov 2009 00:26:13 UTC

    great, i need this good

  9. Stu Sat, 30 Jan 2010 00:28:21 UTC

    Dude, you fixed multiple things for me with this simple CSS! Thanks so much for saving me the unending frustration of why I couldn’t center my article images or the captions weren’t turning out quite right.

    Awesome stuff!

  10. Ryft Braeloch Tue, 02 Feb 2010 02:22:05 UTC

    That’s the CSS. What’s the HTML?
    Ryft Braeloch´s last blog ..Quotables: Dennis Prager My ComLuv Profile

  11. Trey Connell Tue, 02 Feb 2010 08:53:02 UTC

    Hey Ryft – it’s just the standard html that WordPress generates behind the scenes when you insert an image in your post.

  12. Ryft Braeloch Tue, 02 Feb 2010 22:57:13 UTC

    I guess what I mean is, “After inserting the aforementioned CSS into my stylesheet, how do I add captions to images? (I’ve been scouring the web trying to find out how to do that.)
    Ryft Braeloch´s last blog ..Quotables: Dennis Prager My ComLuv Profile

  13. Trey Connell Wed, 03 Feb 2010 09:10:16 UTC

    Ryft – Oh I see. When you create / edit a post, click the little square icon next to the “Upload / Insert” line at the top of the wysiwyg editor. You can then upload an image from your computer. After it uploads, you’ll be presented with a screen with various fields on it. One of those fields is caption. Just fill it in and then click “insert into post”.

    Hope that helps!

  14. oakley Thu, 25 Feb 2010 18:13:14 UTC

    Perfect solution. Thanks a bunch!

  15. M Fri, 26 Feb 2010 15:08:12 UTC

    Excellent, thank you!

  16. Marcus Cuttino Sat, 03 Jul 2010 10:11:52 UTC

    Is there a way to reduce the space between the text in the caption and the caption border. It seems as if there is too much space. Also is there a way to reduce the space between the bottom caption border and the paragraph text beneath it. It seems as if the space there is a little excessive as well. I’ve tried playing with the CSS some but no luck…I’m hoping you might be able to help me out.

  17. Doug Lipman Tue, 03 Aug 2010 07:41:37 UTC

    Oh, thank you! I spent a couple hours trying to modify the CSS for the captions, but couldn’t find it. (The style.css file for my custom theme doesn’t contain it, and I couldn’t find what file was being called that did contain it.)

    By adding the code you gave, I was able to override the other CSS and get the result I wanted.

    I had nearly given up, when I happened on this page. I much appreciate it!

  18. Trey Connell Wed, 04 Aug 2010 17:37:20 UTC

    Glad to help Doug!

  19. Chris Jacobson Sat, 28 Aug 2010 15:21:57 UTC

    My content CSS font is overriding the image captions’ CSS and the font size and styling is the same as my content. Even when using the above CSS, the font size and styling doesn’t change. How can I override this?
    Chris Jacobson´s last blog ..WordPress Releases 301- Comes Out with Quick FixMy ComLuv Profile

Comments

CommentLuv Enabled