CSS Transition - Fade Element on Hover only

后端 未结 2 973
感情败类
感情败类 2020-12-11 19:02

Is it possible to have a css transition that fades an element in on hover but simply hides the element when the mouse leaves.

i.e. hover in = fade for 0.5 seconds |

2条回答
  •  悲哀的现实
    2020-12-11 19:41

    Yes, you can achieve this using CSS3 transitions. Essentially, your CSS should look like this:

    #myLink {
        opacity: 0;
    }
    
    #myLink:hover {
        opacity: 1;
        -webkit-transition: all 0.2s ease-in-out;
        -moz-transition: all 0.2s ease-in-out;
        -o-transition: all 0.2s ease-in-out;
        transition: all 0.2s ease-in-out;
    }
    

    And here's a jsFiddle to demonstrate: Fiddle

提交回复
热议问题