2

次の html を検討してください。

<div>
<a href="#" title="image"><img src="http://s9.postimg.org/lqikvh05r/black_shirt.jpg" /></a>
<h3>Some text here but if this gets long it will pass the image and not wrap</h3>
</div>

画像のサイズを事前に知らなくても、テキストを画像と同じ幅にして、長くなった場合に折り返す CSS の方法はありますか?

これが問題のフィドルです-> http://jsfiddle.net/qRGM5/

4

2 に答える 2

0

私はそれがおそらく明白であり、あなたが探しているものではないかもしれないことを知っています. ただし、画像に最大幅を設定したい場合は機能します。

#picture img {
max-width:100px;
}
#picture {
max-width:100px;
}
#text{
max-width:inherit;
}

<div id="picture">
<a href="#" title="image">
<img src="http://s9.postimg.org/lqikvh05r/black_shirt.jpg"     /></a>
<h3><div id="text" >Some text here but if this gets long
 it will pass the image and not wrap</div></h3>

于 2013-04-11T23:44:59.607 に答える