1. 程式人生 > >如何用css給input的placeholder設置顏色

如何用css給input的placeholder設置顏色

註意 kit size pan title 存在 默認顏色 情況 input標簽

我在做頁面的時候遇到過這種情況,在input標簽中有默認字,但是設計稿上的顏色和input標簽中的placeholder的默認顏色不一致。雖然我們可以在js中寫出,但是有點過於麻煩了。

所以我就用css來給它設置了一下(註意css中有可能存在兼容性問題,如果實在不行還得用js。不過一般要求不嚴可以用這個偷偷懶)。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>    
        <style>
             #txt
{        height:100%;           width:230px;           font-size:12px;color:red;         }          #txt::-webkit-input-placeholder{            color:red;          } </style> </head> <body> <input type="text" id="txt" placeholder="請輸入主題或關鍵詞"/> </body> </html>

這樣我們就可以用更少的時間做更多的事了。

如何用css給input的placeholder設置顏色