How can I make image caption width same as image? Now I have the following code:
&
You can apply display:table;
and an arbitrary initial width, eg. width:7px;
to the parent block like figure
and everything will work as expected!
Here is a live demo: http://jsfiddle.net/blaker/8snwd/
This solution's limitation is that IE 7 and earlier do not support display:table;
and IE 8 requires your doctype to be !DOCTYPE
.
Sources: