UED给出了一个需求,但愿<input>
被选中时,将光标变为绿色。我赶忙搜索解决方案,发现思路大可能是:css
input { color: #0f0; }
这种方法的确能改变光标的默认颜色,可是负面做用是,输入的文字也变成了绿色。html
幸运的是在Stack overflow上找到了一个靠谱的答案:web
input, textarea { font-size: 24px; padding: 10px; color: #0f0; text-shadow: 0px 0px 0px #000; -webkit-text-fill-color: transparent; } input::-webkit-input-placeholder, textarea::-webkit-input-placeholder{ text-shadow: none; -webkit-text-fill-color: initial; }
完整代码以下:spa
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> input, textarea { color: #0f0; text-shadow: 0px 0px 0px #000; -webkit-text-fill-color: transparent; } input::-webkit-input-placeholder, textarea::-webkit-input-placeholder{ text-shadow: none; -webkit-text-fill-color: initial; } </style> </head> <body> <input type="text" placeholder="test"> <p></p> <textarea name="" cols="30" rows="10"></textarea> </body> </html>
参考自:http://jsfiddle.net/8k1k0awb/.net