CSS

::placeholder

::placeholder

这是一项实验技术

由于该技术的规格不稳定,请查看兼容性表以了解各种浏览器的使用情况。还请注意,随着规范的变化,实验技术的语法和行为在未来版本的浏览器中可能会发生变化。

::placeholder CSS 伪元素代表的占位符文本一的形式元素。

::placeholder { color: blue; font-size: 1.5em; }

只有应用于::first-line伪元素的 CSS 属性的子集可以::placeholder在其选择器中使用的规则中使用。

注意:在Firefox中,默认情况下,占位符文本的外观是半透明的灰色。

语法

::placeholder

示例

HTML

<input placeholder="Type something here!">

CSS

input::placeholder { color: red; font-size: 1.2em; font-style: italic; }

结论

规范

规范状态解释
CSS Pseudo-Elements Level 4The definition of '::placeholder' in that specification.Working DraftInitial definition.

浏览器兼容性

FeatureChromeFirefox (Gecko)EdgeInternet ExplorerOperaSafari
Basic support5751.0 (51.0)1No supportNo support4410.1
Partial support with prefixSupportedSupportedSupported10 -ms-Supported5 -webkit-

FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support575752.0 (52.0)No support10.3
Partial support with prefix2.1 -webkit-SupportedSupported10 -ms-37 -webkit-4.3 -webkit-