我建议您使用正确的标签:figure和figcaption,无论如何,这是一个干净的解决方案,也适用于您的标记,您可以在这个FIDDLE中看到结果。
figure, #container {
display: table;
max-width: 100%;
width: auto !important;
}
img {
display: table-row;
max-width: 100%;
width:100%;
}
figcaption, #text {
display: table-caption;
max-width: inherit;
caption-side: bottom;
word-wrap: break-word;
}
<!--[if lt IE 9]><style type="text/css">
img,
figcaption {
width: auto !important;
}
</style><![endif]-->
<figure>
<img src="http://dummyimage.com/300x200/c7c1c7/fff.jpg" alt="alt text" />
<figcaption>Several standard dimensions are included in dummyimage.com including ad sizes and screen resolution sizes.</figcaption>
</figure>
<!-- YOUR MARKUP #2 -->
<div id="container">
<img src="http://dummyimage.com/300x200/c7c1c7/fff.jpg" alt="alt text" />
<div id="text">Several standard dimensions are included in dummyimage.com including ad sizes and screen resolution sizes.</div>
</div>
我还建议查看此博客文章以更好地调整图像大小