Possible Duplicate:
Caption in Page adding unwanted 10px to width
这是一篇帖子的屏幕截图。我已经给了。wp标题为黑色背景,因此可以看到右侧额外的10px边距。顶部的10px边距是有目的的。I don\'t know what is causing the 10px margin on the right and there is nothing else I can find in my code that would create it... I\'ve even eliminated everything in my CSS to rid it of this margin but it still remains.
一种解决方案是将图像宽度设置为100%,但这会在我的帖子中为指定的图像大小添加10个像素,从而使图像水平扭曲10个像素。This problem is only happening with captions, not general images.
您可以在此处看到问题:http://themeforward.com/demo2/sample-elements/
/*////////////////////////////////////////////////////////////////////
// 30. Images
////////////////////////////////////////////////////////////////////*/
img {
border:0;
overflow:hidden;
z-index:5!important
}
#post_content img, p img {
height:auto;
z-index:5!important;
max-width:650px;
margin-top:9px!important
}
#content img {
display:block;
clear:both;
max-width:100%!important
}
/* Images - Aligning */
.aligncenter {
clear:both;
display:block;
margin:0 auto 10px
}
.alignleft {
display:block;
float:left;
margin:0 25px 10px 0
}
.alignright {
display:block;
float:right;
margin:0 0 10px 25px
}
/*////////////////////////////////////////////////////////////////////
// 31. Image captions
////////////////////////////////////////////////////////////////////*/
.wp-caption img {
border:none;
height:auto;
background:#F5F5F5;
max-width:650px!important
}
.wp-caption p.wp-caption-text {
font-size:85%;
padding:0!important;
margin:2px 0 5px!important;
line-height:175%!important;
font-style:italic;
text-align:left
}
.wp-caption { background:#000 }
/* Image Captions */
.alignleft.wp-caption { margin:0 25px 10px 0 }
.alignright.wp-caption { margin:9px 0 10px 25px }
.aligncenter.wp-caption { }
最合适的回答,由SO网友:AndrettiMilas 整理而成
答案就在函数中。php
function wpse14305_img_caption( $empty_string, $attributes, $content ){
extract(shortcode_atts(array(
\'id\' => \'\',
\'align\' => \'alignnone\',
\'width\' => \'\',
\'caption\' => \'\'
), $attributes));
if ( empty($caption) )
return $content;
if ( $id ) $id = \'id="\' . esc_attr($id) . \'" \';
return \'<div \' . $id . \'class="wp-caption \' . esc_attr($align) . \'">\' . do_shortcode( $content ) . \'<p class="wp-caption-text">\' . $caption . \'</p></div>\';
}
add_filter( \'img_caption_shortcode\', \'wpse14305_img_caption\', 10, 3 );