私はCSSスプライトテクニックを次のような背景画像で使用しています。
アイコンのCSSコード:
div.icon {
background-color: transparent;
background-image: url("/images/icons.png");
background-position: 0 0;
background-repeat: no-repeat;
display: inline-block;
height: auto;
vertical-align: text-top;
width: auto;
}
div.icon:empty {
width:16px;
height:16px;
}
div.icon:not(:empty) {
padding-left:20px;
}
div.icon.attenuation {
background-position: 0 0;
}
私のアイコンは次のように使用できます。
<div class="icon warning"></div>
アイコンの中に次のようなテキストを入れたいです。
<div class="icon warning">There is a warning on this page</div>
ただし、問題は、背景画像がテキスト領域全体をカバーしていることです。
問題は、画像の一部のみを要素の一部の背景画像として使用するにはどうすればよいですか?
ノート:
- forに設定
width
しても効果はありません。16px
div.icon