2015-02-11 101 views
0

当我悬停divbackground-image已被background:#444覆盖,任何想法如何显示悬停时的背景图像?悬停背景图片已不存在

body{ 
 
    background:#ccc; 
 
    } 
 
.mall_vjprofile_changebg{ 
 
\t float:left; 
 
\t color:#fff; 
 
\t font-size:14px; 
 
\t background-image:url(../img/camera.png); 
 
\t background-repeat:no-repeat; 
 
\t background-position:5px 5px; 
 
\t padding:10px; 
 
\t text-indent:30px; 
 
\t margin:5px; 
 
\t cursor:pointer; 
 
\t border:1px solid #fff; 
 
} 
 
.mall_vjprofile_changebg:hover{ 
 
\t background-image:url(../img/camera.png); 
 
\t background-repeat:no-repeat; 
 
\t background-position:5px 5px; 
 
\t border:1px solid #fff; 
 
\t background:#444; \t 
 
\t color:#fff; 
 
\t \t \t 
 
}
<div id="mall_vjprofile_changebg" class="mall_vjprofile_changebg">Camera</div>

+1

正确读取,因为你是重新分配的background属性 – 2015-02-11 03:15:38

回答

1

取下悬停状态的CSS的background:#444;

编辑:

如果你需要的背景颜色也尽量在一个声明中结合背景样式:

background: #444 url(../img/camera.png) 5px 5px no-repeat; 
+0

的文件,但我需要'背景:#444' – 2015-02-11 03:17:29

1

从悬停状态删除background: #444。如果你想保持的背景颜色编写代码是这样的:

.mall_vjprofile_changebg:hover{ 
    background-image:url(../img/camera.png); 
    background-repeat:no-repeat; 
    background-position:5px 5px; 
    border:1px solid #fff; 
    background-color: #444; 
    color:#fff; 

} 
+0

但我需要'背景:#444' – 2015-02-11 03:15:01

+0

然后添加另一个包装div以获得背景颜色 – Filth 2015-02-11 03:15:38

+0

您可以将背景写为背景:url(path/to/img)#444 no-repeat; 这将使颜色回落 – ChrisJ 2015-02-11 03:17:14

1

background可以被用来为一个或一个以上的设定值:background-clipbackground-colorbackground-imagebackground-originbackground-positionbackground-repeatbackground-sizebackground-attachmentMDN

,所以你需要删除background:#444处于悬停状态,并设置

background-color:#444; 

或类似

background: url("../image/camera.png") no-repeat 5px 5px #444; 
+1

这是正确的答案。我们其余的人过度认为它;-) – 2015-02-11 03:19:31

1

当您设置background: #fff它overwritting其他简写属性。

您需要:

background-color: #444; 

您还可以使用:

background: #444 url(../img/camera.png) 5px 5px no-repeat;