[英]Changing font color and background image when hovering over button
For my navigation bar, I have several buttons. 对于我的导航栏,我有几个按钮。 When hovering over a button, I want the background image to change and I want the font color to change.
将鼠标悬停在按钮上时,我想更改背景图像,并且要更改字体颜色。 The background image is changing fine but I can't get the font color to change.
背景图像变化很好,但我无法更改字体颜色。 I included both
.but1
and .but2
to give an idea of what each of the buttons look like but so far I've only edited .but1
for the hover text. 我同时包含了
.but1
和.but2
以了解每个按钮的外观,但到目前为止,我只为悬停文本编辑了.but1
。
Any help would be appreciated. 任何帮助,将不胜感激。 Thanks!
谢谢!
CSS: CSS:
#buttons {
width:665px;
background:url(images/bg_but.jpg) left top no-repeat;
text-align:center;
height:46px;
margin-left:450px;
}
#buttons a {
font-family:OVerlock, cursive;
font-size:20px;
display:block;
float:left;
height:34px;
text-decoration:none;
color:#303030;
padding-top:12px;
padding-left:0;
text-align:center;
}
.but1 {
background:url(images/but1-4.png) left top no-repeat;
width:134px;
}
.but1:hover {
color:#FFF;
background:url(images/but11.png) left top no-repeat;
}
.but2 {
background:url(images/but2.png) left top no-repeat;
width:132px;
}
.but2:hover {
background:url(images/but22.png) left top no-repeat;
}
HTML 的HTML
<div id="buttons">
<a href="#" class="but1" title="">Home</a>
<a href="#" class="but2" title="">Projects</a>
<a href="#" class="but3" title="">Paintings</a>
<a href="#" class="but4" title="">About</a>
<a href="#" class="but5" title="">Contact</a>
</div>
The selector #buttons a
is more specific than .but1:hover
, so it will take precedence. 选择器
#buttons a
比.but1:hover
更具体,因此它将具有优先权。
Change it to #buttons .but1:hover
and it will be more specific. 将其更改为
#buttons .but1:hover
,它将更加具体。
simply add your important into .but1:hover
like the code below 只需将您的重要内容添加到
.but1:hover
就像下面的代码一样
.but1:hover {
color:#FFF !important;
background:url(images/but11.png) left top no-repeat;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.