How to change placeholder color on focus?

后端 未结 9 912
有刺的猬
有刺的猬 2020-12-04 11:05

How to change the color of placeholder when focus the input field? I use this css to set the default color, but how to change it on focus?

::-webkit-input-pl         


        
相关标签:
9条回答
  • 2020-12-04 11:33

    This works for me:

    input:focus::placeholder {
      color: blue;
    }
    
    0 讨论(0)
  • 2020-12-04 11:34

    From Firefox 19: The :-moz-placeholder pseudo-class that matches form elements with the placeholder attribute has been removed, and the ::-moz-placeholder pseudo-element has been added instead.

    input:focus::-moz-placeholder { color: transparent; }
    
    0 讨论(0)
  • 2020-12-04 11:39

    Try this, this should work :

    input::-webkit-input-placeholder {
        color: #999;
    }
    input:focus::-webkit-input-placeholder {
        color: red;
    }
    
    /* Firefox < 19 */
    input:-moz-placeholder {
        color: #999;
    }
    input:focus:-moz-placeholder {
        color: red;
    }
    
    /* Firefox > 19 */
    input::-moz-placeholder {
        color: #999;
    }
    input:focus::-moz-placeholder {
        color: red;
    }
    
    /* Internet Explorer 10 */
    input:-ms-input-placeholder {
        color: #999;
    }
    input:focus:-ms-input-placeholder {
        color: red;
    }
    

    Here is an example : http://jsfiddle.net/XDutj/27/

    0 讨论(0)
  • 2020-12-04 11:39

    The following worked for me:

    input:focus::-webkit-input-placeholder
    {
        color: red;
    }
    
    0 讨论(0)
  • 2020-12-04 11:42

    Try this:

    HTML

    <input type='text' placeholder='Enter text' />
    

    CSS

    input[placeholder]:focus { color: red; }
    
    0 讨论(0)
  • 2020-12-04 11:44

    Use star * to select everything

    *::-webkit-input-placeholder { color: #999; }
    
    
    *:-moz-placeholder { color: #999; }
    
    
    *::-moz-placeholder { color: #999; }
    
    
    *:-ms-input-placeholder { color: #999; }
    
    0 讨论(0)
提交回复
热议问题