How do I auto-hide placeholder text upon focus using css or jquery?

后端 未结 26 1749
长情又很酷
长情又很酷 2020-11-28 00:39

This is done automatically for every browser except Chrome.

I\'m guessing I have to specifically target Chrome.

Any solutio

相关标签:
26条回答
  • 2020-11-28 01:22

    Sometimes you need SPECIFICITY to make sure your styles are applied with strongest factor id Thanks for @Rob Fletcher for his great answer, in our company we have used

    So please consider adding styles prefixed with the id of the app container

        #app input:focus::-webkit-input-placeholder, #app  textarea:focus::-webkit-input-placeholder {
            color: #FFFFFF;
        }
    
        #app input:focus:-moz-placeholder, #app textarea:focus:-moz-placeholder {
            color: #FFFFFF;
        }

    0 讨论(0)
  • 2020-11-28 01:22

    For a pure CSS based solution:

    input:focus::-webkit-input-placeholder  {color:transparent;}
    input:focus::-moz-placeholder   {color:transparent;}
    input:-moz-placeholder   {color:transparent;}
    

    Note: Not yet supported by all browser vendors.

    Reference: Hide placeholder text on focus with CSS by Ilia Raiskin.

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