liのサイズをイメージのサイズと同じにして、paddingで内側に余白を取りたいのですが、イメージのサイズより広がってしまいます。
テキストは短いのから長いのまであって、長いときにはBRを使わずに余白で折り返したいのですが、うまくイメージ内に収まってくれません。
cssは独学ですので、きっと間違いだらけだと思います。
どなたかどうぞ宜しくお願いします。
#contents #img1 #li1 {
background-image:url(../images/■■.gif);
background-repeat:no-repeat;
width:302x;
height:60px;
margin-top:0px;
margin-right:0px;
margin-bottom:0px;
margin-left:0px;
padding-top:0px;
padding-right:0px;
padding-bottom:0px;
padding-left:0px;
}
#contents #img1 #li2 {
background-image:url(../images/●●.gif);
background-repeat:no-repeat;
width:302px;
height:63px;
margin-top:0px;
margin-right:0px;
margin-bottom:0px;
margin-left:0px;
padding-top:0px;
padding-right:0px;
padding-bottom:0px;
padding-left:0px;
}
<div id="contents">
<ul id="img1">
<li id="li1">ああああああああ</li>
<li id="li2">いいいいいいいいいいいいいいいいいいいいいいいいいい</li>
</ul>
</div>
width で指定するのは「内容」の幅なので、左右の padding を指定するとその要素自体の幅は「内容の幅」+ padding となります。
( IE6 の互換モードでは要素の幅が padding も含めた大きさになります。)
そこで、要素の幅を画像に合わせるには
といった方法があります。
ありがとうございます。
イメージの幅以上にはしたくなかったので、liの中にdivを追加しました。
バッチリでした。