Firefox: Transition placeholder opacity

前端 未结 2 422
有刺的猬
有刺的猬 2020-12-21 06:35

I wanted to make input placeholder fade smoothly on focus using transition, but can\'t get it to work in FF.



        
2条回答
  •  星月不相逢
    2020-12-21 07:17

    How about doing it like this? Instead of using opacity, switch the color shades

    Demo

    
    
    input[type=text]:-moz-placeholder {
    color: #000;
    transition: color 1s;
    }
    
    input[type=text]:focus:-moz-placeholder {
        color: #aaa;
    }
    
    input[type=text]::-webkit-input-placeholder {
        color: #000;
        transition: color 1s;
    }
    
    input[type=text]:focus::-webkit-input-placeholder {
        color: #aaa;
    }
    

    Certainly you can use opacity if you want but you can see the result yourself and decide what's better for you, opacity demo

    Note: Use ::-moz-placeholder to support +19 Ver

提交回复
热议问题