Firefox: Transition placeholder opacity

前端 未结 2 402
有刺的猬
有刺的猬 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" placeholder="some cool text"/>
    
    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

    0 讨论(0)
  • 2020-12-21 07:40

    Transition on ::placeholder should not be supported by any browser as it is not defined by specification, so that can be considered non-standard behavior. The fact that Firefox does not support it is correct behavior:

    https://bugzilla.mozilla.org/show_bug.cgi?id=1115623

    By specification, only ::after and ::before pseudo-elements have transition property enabled. All other pseudo-elements don't.

    Here's more: Why is a transition property on the placeholder pseudoelement valid in Chrome?

    0 讨论(0)
提交回复
热议问题