[英]CSS hover not working properly in my menu bar
I am trying to change the background-color
of a menu, while mouse-hover
. 我试图在
mouse-hover
时更改菜单的background-color
。 But it is not working. 但这是行不通的。
I have used the following CSS code: 我使用了以下CSS代码:
#access a:hover{
background: -moz-linear-gradient(center top , #F99733, #E47300) repeat scroll 0 0 transparent;
}
Please take a look at the page CLICK HERE 请看一下页面点击这里
#access a:hover{
background: -moz-linear-gradient(center top , #F99733, #E47300) repeat scroll 0 0 transparent;
background: -webkit-linear-gradient(center top , #F99733, #E47300) repeat scroll 0 0 transparent;
background: -o-linear-gradient(center top , #F99733, #E47300) repeat scroll 0 0 transparent;
background: -ms-linear-gradient(center top , #F99733, #E47300) repeat scroll 0 0 transparent;
}
Try using this , 尝试使用这个,
background: linear-gradient(....
background: -moz-linear-gradient(.... /// FF3.6+
background: -webkit-linear-gradient(.... /// Chrome10+,Safari5.1+
background: -o-linear-gradient(.... /// Opera 11.10+
background: -ms-linear-gradient(.... /// IE10+
Personally I like using a grey inset
box-shadow
to style my element and then I can simply swap the background colours on hover. 就个人而言,我喜欢使用灰色
inset
box-shadow
来设置我的元素的样式,然后我可以在悬停时简单地交换背景颜色。
<div>
Example
</div>
div
{
border: 1px solid black;
padding: 10px;
font-size: 20px;
background-color: #0ff;
box-shadow: inset 0px -50px 75px -50px #000;
-moz-box-shadow: inset 0px -50px 75px -50px #000;
-webkit-box-shadow: inset 0px -50px 75px -50px #000;
}
div:hover
{
background-color: #bff;
}
http://jsfiddle.net/gvee/5Q5h9/ http://jsfiddle.net/gvee/5Q5h9/
Different browsers use different gradient rules, try using the code below: 不同的浏览器使用不同的渐变规则,请尝试使用以下代码:
div:hover {
background: -webkit-gradient(linear, 0 0, 0 bottom, from(#F99733), to(#E47300)); /* safari & chrome */
background: -moz-linear-gradient(#F99733, #E47300); /* Firefox */
-ms-filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFF99733,endColorstr=#FFE47300); /* IE8 */
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFF99733,endColorstr=#FFE47300); /* IE 7 */
zoom: 1;
background: linear-gradient(#F99733, #E47300);
}
It doesn't work because its having issues with your :focus
pseudo selector which is applied to your <a>
. 它不起作用,因为它与应用于您
<a>
:focus
伪选择器有关。
First you need to understand that you are only supporting gecko based browsers (Mozilla Firefox) by adding the vendor prefix of -moz to your CSS. 首先,您需要通过将-moz的供应商前缀添加到CSS来了解您仅支持基于gecko的浏览器(Mozilla Firefox)。
There's a website that helps you make gradients so you can copy and paste them and they have an image as a fallback so it looks good in older browsers too. 有一个网站可以帮助您制作渐变,因此您可以复制和粘贴渐变 ,并且它们具有备用图像,因此在较旧的浏览器中看起来也不错。
So it will end up looking like this: 所以最终看起来像这样:
#access li a:hover,
#access li a:focus {
background: #f99733;
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPHJhZGlhbEdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgY3g9IjUwJSIgY3k9IjUwJSIgcj0iNzUlIj4KICAgIDxzdG9wIG9mZnNldD0iMCUiIHN0b3AtY29sb3I9IiNmOTk3MzMiIHN0b3Atb3BhY2l0eT0iMSIvPgogICAgPHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjZTQ3MzAwIiBzdG9wLW9wYWNpdHk9IjEiLz4KICA8L3JhZGlhbEdyYWRpZW50PgogIDxyZWN0IHg9Ii01MCIgeT0iLTUwIiB3aWR0aD0iMTAxIiBoZWlnaHQ9IjEwMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-radial-gradient(center, ellipse cover, #f99733 0%, #e47300 100%);
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,#f99733), color-stop(100%,#e47300));
background: -webkit-radial-gradient(center, ellipse cover, #f99733 0%,#e47300 100%);
background: -o-radial-gradient(center, ellipse cover, #f99733 0%,#e47300 100%);
background: -ms-radial-gradient(center, ellipse cover, #f99733 0%,#e47300 100%);
background: radial-gradient(ellipse at center, #f99733 0%,#e47300 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f99733', endColorstr='#e47300',GradientType=1 );
}
I find that this works for me in most cases and its based on what I understand your specific needs are. 我发现这在大多数情况下都对我有效,它基于我对您的特定需求的了解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.