Make input value uppercase in CSS without affecting the placeholder

前端 未结 2 1852
既然无缘
既然无缘 2020-12-09 14:38

Is there a way I can make an input value uppercase without making the placeholder uppercase?

Seems like I get one or the other. I\'d prefer to do this cleanly just

2条回答
  •  生来不讨喜
    2020-12-09 15:12

    Each browser engine has a different implementation to control placeholder styling. Use the following:

    jsBin example.

    input { 
        text-transform: uppercase;
    }
    ::-webkit-input-placeholder { /* WebKit browsers */
        text-transform: none;
    }
    :-moz-placeholder { /* Mozilla Firefox 4 to 18 */
        text-transform: none;
    }
    ::-moz-placeholder { /* Mozilla Firefox 19+ */
        text-transform: none;
    }
    :-ms-input-placeholder { /* Internet Explorer 10+ */
        text-transform: none;
    }
    ::placeholder { /* Recent browsers */
        text-transform: none;
    }
    

    Needless to say, this only works in browsers that can handle placeholders. (IE9/10+)

提交回复
热议问题