我會建議你使用正確的標籤:圖和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>
我還建議調整到看一看this blog post美好形象
那麼,什麼是終極目標 - 文本居中在圖像或有div和圖像大小相同?另外,你會願意使用jquer/javascript嗎? –
我認爲你可能會這樣做>>> http://jsfiddle.net/HUsRm/10/ –