简体   繁体   English

CSS3过渡效果,用于将鼠标悬停在和关闭

[英]CSS3 transition effect for hover on AND off

I have made a hover effect for when the mouse hovers over the nav button, however it just pops back into place when the mouse leaves. 当鼠标悬停在导航按钮上时,我已经做出了悬停效果,但是当鼠标离开时,它会弹出回到原位。 I am wondering how to properly achieve the effect of hovering on and off. 我想知道如何正确地实现上下悬停的效果。

I have tried adding the transition code to both a and a:hover, however when I do that there is some weird unwanted transition effect every time I navigate to, or refresh the page. 我曾尝试将过渡代码添加到a和a:hover上,但是当我这样做时,每次导航到或刷新页面时都会出现一些奇怪的不需要的过渡效果。

Here is the code: 这是代码:

nav a {
text-decoration: none;
padding: 25px 20px;
transition-property: background color ease-in-out;
transition-duration: 300ms;
transition-timing-function: linear;
}
nav a:hover {
background-color: #28292B;
transition-property: background color ease-in-out;
transition-duration: 300ms;
transition-timing-function: linear;
}

Thanks everyone! 感谢大家!

Do it like this instead: 改为这样做:

 nav a {
text-decoration: none;
padding: 25px 20px;
-o-transition:.5s ease-in-out;
-ms-transition:.5s ease-in-out;
-moz-transition:.5s ease-in-out;
-webkit-transition:.5s ease-in-out;
transition:.5s  ease-in-out;
}
nav a:hover {
background-color: #28292B;
    color:white;
}

JSFiddle Example JSFiddle示例

Simple and easy.:) 简单容易。:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM