以前は、画像を上に配置し、画像の下のテキストを揃えて、画像の幅の境界内に収まるようにする方法を知っていました。しかし、今はこれを行う方法がわかりません。これはどのように達成されますか?
365885 次
5 に答える
66
あなたの HTML:
<div class="img-with-text">
<img src="yourimage.jpg" alt="sometext" />
<p>Some text</p>
</div>
画像の幅がわかっている場合、CSS は次のようになります。
.img-with-text {
text-align: justify;
width: [width of img];
}
.img-with-text img {
display: block;
margin: 0 auto;
}
そうしないと、画像の下のテキストがフリーフローになります。これを防ぐには、コンテナに幅を設定してください。
于 2009-08-04T00:20:34.553 に答える
5
テキストを正当化できるようにするには、画像の幅を知る必要があります。画像の通常の幅を使用することも、別の幅を使用することもできますが、IE 6は不機嫌になり、縮尺が合わない場合があります。
必要なものは次のとおりです。
<style type="text/css">
#container { width: 100px; //whatever width you want }
#image {width: 100%; //fill up whole div }
#text { text-align: justify; }
</style>
<div id="container">
<img src="" id="image" />
<p id="text">oooh look! text!</p>
</div>
于 2009-08-04T00:22:10.623 に答える
5
これにより、画像の下の「A」が中央に配置されます。
<div style="text-align:center">
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/opentoselect.gif" />
<br />
A
</div>
それは ASP.Net であり、HTML を次のようにレンダリングします。
<div style="text-align:center">
<img id="Image1" src="Images/opentoselect.gif" style="border-width:0px;" />
<br />
A
</div>
于 2009-08-03T23:47:56.890 に答える