Fade Effect on Link Hover?

前端 未结 4 1203
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 04:28

on many sites, such as http://www.clearleft.com, you\'ll notice that when the links are hovered over, they will fade into a different color as opposed to immediately switchi

4条回答
  •  日久生厌
    2020-12-02 04:58

    I know in the question you state "I assume JavaScript is used to create this effect" but CSS can be used too, an example is below.

    CSS

    .fancy-link {
       color: #333333;
       text-decoration: none;
       transition: color 0.3s linear;
       -webkit-transition: color 0.3s linear;
       -moz-transition: color 0.3s linear;
    }
    
    .fancy-link:hover {
       color: #F44336;
    }
    

    HTML

    My Link
    

    And here is a JSFIDDLE for the above code!


    Marcel in one of the answers points out you can "transition multiple CSS properties" you can also use "all" to effect the element with all your :hover styles like below.

    CSS

    .fancy-link {
       color: #333333;
       text-decoration: none;
       transition: all 0.3s linear;
       -webkit-transition: all 0.3s linear;
       -moz-transition: all 0.3s linear;
    }
    
    .fancy-link:hover {
       color: #F44336;
       padding-left: 10px;
    }
    

    HTML

    My Link
    

    And here is a JSFIDDLE for the "all" example!

提交回复
热议问题