div.wp-caption shortcode should have width of img, rather than add +10px
|Reported by:||mgk25||Owned by:|
In WordPress 3.1, file wp-includes/media.php function img_caption_shortcode() ends with the line
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">'
This line unfortunately hardwires into WordPress (apparently since version 2.6) a style-sheet issue, namely it makes the <div> that combines an image with its caption text 10 pixels wider that the image itself.
Why, and why exactly 10px?
This seems a bad idea for several reasons:
- The addition of a caption needlessly changes horizontal spacing around a floating image by 10px, which looks awkward if a posting includes several left-floating images, some of which have captions and some of which do not (and therefore use no caption shortcode). Those images that have captions will have 10px additional space compared to those that do not, leading to an uneven appearance that can't be fixed neatly in theme CSS.
- Any desired additional space could easily be offered in the theme CSS via a margin, and there is no need to hardwire this into the width, Such stylistic choices (such as 10px) should really be left to the theme CSS, rather than hardwired into WordPress.
Please replace in the above line the term
(10 + (int) $width)
in other words remove the hardwired additional width for the img+caption containing div.
Users have complained about this issue many times in the support forum, and it clearly causes a lot of confusion and unexpected behaviour, but I haven't seen it yet filed as a bug:
A related complaint: