あなたのHTMLの場合:この要素にカーソルを移動div
のbackground-position
を変更することは、単なる問題です。
.close:hover > .closebutt {
background-position: 0px -14px;
}
このように、background-position
は、その親がホバリングされたときにのみ変化します。
これは、あなたの質問を更新する前に、私は投稿元の答えです: 私は通常、このように私のHTMLを整理するには、
<a href="#" class="button">
<div class="glyph"></div>
<div class="text">Button text</div>
</a>
EDIT:@Paul D.ウェイトは、コメントで指摘してa
にはインライン要素のみを含めることができるため、このHTML構造はHTML4では無効です。したがって、これを修正するには、span
をa
の子として持つこのように構造を変更することができます。 CSSは同じままで、必要に応じて最終的にdisplay: block
を追加します。あなたもこのような方法で、ボタンに新しいクラスを追加するスタイルを変更することができます。このように
.button {
/* .. general style */
}
.button > .glyph {
/* .. general style for the glyph, like size or display: block */
background-image: url('..');
background-repeat: no-repeat;
background-position: left top;
}
.button > .text {
/* .. general style for the text, like font-size or display: block */
text-decoration: none;
}
.button:hover > .glyph {
/* .. change the glyph style when the button is hovered */
background-position: left bottom;
}
.button:hover > .text {
/* .. change the text style when the button is hovered */
text-decoration: underline;
}
:
<a href="#" class="button">
<span class="glyph"></span>
<span class="text">Button text</span>
</a>
と、このようにあなたのCSS
<a href="#" class="button red">
<div class="glyph"></div>
<div class="text">Button text</div>
</a>
<a href="#" class="button gray">
<div class="glyph"></div>
<div class="text">Button text</div>
</a>
そして、 CSS
.button.red {
background-color: red;
}
.button.red > .text {
color: black;
}
.button.gray {
background-color: darkgray;
}
.button.gray > .text {
color: white;
}
HTMLを表示します。あなたを助けるために私たちを助けてください。 –