- HTML中文网
- 联系QQ:88526
- QQ交流群

- 微信公众号

::placeholder
E::placeholder { sRules }
Firefox支持该伪元素使用text-overflow属性来处理溢出问题。
::placeholder的使用示例:
<input type="text" placeholder="占位符"/>input::-webkit-input-placeholder { color: #999; } input:-ms-input-placeholder { // IE10+ color: #999; } input:-moz-placeholder { // Firefox4-18 color: #999; } input::-moz-placeholder { // Firefox19+ color: #999; }
兼容性:
浅绿 = 支持
红色 = 不支持
粉色 = 部分支持
IE | Firefox | Chrome | Safari | Opera | iOS Safari | Android Browser | Android Chrome |
---|---|---|---|---|---|---|---|
6.0-9.0 | 2.0-3.6 | 4.0- 43.0-webkit- | 3.1-4.0 | 15.0- 28.0-webkit- | 3.2-4.1 | 2.1 -4.4.4-webkit- | 18.0 -40.0-webkit- |
10.0- 11.0-ms- | 4.0 -18.0-moz- #1 | 5.0 -8.1-webkit- | 4.3 -8.1-webkit- | ||||
19.0- 38.0-moz- |
#1表示::-moz-placeholder 伪元素在Firefox 19+替代了之前的 :-moz-placeholder 伪类
<!DOCTYPE html> <html lang="zh-cmn-Hans"> <head> <meta charset="utf-8" /> <style> input::-webkit-input-placeholder { color: green; } input:-ms-input-placeholder { // IE10+ color: green; } input:-moz-placeholder { // Firefox4-18 color: green; } input::-moz-placeholder { // Firefox19+ color: green; } </style> </head> <body> <input id="test" placeholder="Placeholder text!"> </body> </html>
点击 "运行实例" 按钮查看在线实例
推荐手册