重要なのは、要素または親コンテナーの幅を設定しないことです。img親.imageが単純にフロートされているか、他の方法でコンテンツのサイズに縮小するように調整されている場合、これは機能するはずです。
以前floatはシュリンクラップの側面を達成してposition: absolute;いましたが、同じようにしdisplay: inline-block;ます。
JS Binにデモがあり、jQuery を使用して画像を交換しますが、要素の幅には何もしません。CSS を以下に再掲します。
.image {
float: left; // for the shrink wrap
padding: 1em; // To achieve the bordered effect
background-color: #666; // just for contrast
-moz-border-radius: 2em; // for that web 2.0 goodness...
-webkit-border-radius: 2em;
border-radius: 2em;
}
.image img {
-moz-border-radius: 2em; // no width, anywhere. Presumably width: auto, would
-webkit-border-radius: 2em; // work, but that's redundant, since it's the default
border-radius: 2em;
}
.image img + .caption {
width: 100%; // forcing the .caption to take up 100% of the width
background-color: #ffa; // of its parent, except for the padding, so that it's
} // the same width as the image above.