CSS

插入光标颜色 | caret-color

caret-color

caret-color 属性用来定义插入光标(caret)的颜色,这里说的插入光标,就是那个在网页的可编辑器区域内,用来指示用户的输入具体会插入到哪里的那个一闪一闪的形似竖杠|的东西。

/* Keyword values */ caret-color: auto; caret-color: transparent; caret-color: currentColor; /* <color> values */ caret-color: red; caret-color: #5729e9; caret-color: rgb(0, 200, 0 caret-color: hsla(228, 4%, 24%, 0.8

附注:一些浏览器可能还会把该属性应用到别的类型的光标中,比如有一种光标叫做“导航光标“(navigation caret),它和我们上面说的“插入光标”(insertion caret)不同的是,导航光标是在不可编辑区域内来回移动的,而不是在可编辑区域内。

初始值auto
适用元素all elements
是否是继承属性yes
适用媒体interactive
计算值auto is computed as specified and <color> values are computed as defined for the color property.
Animation typea color
正规顺序per grammar

语法

auto

附注:auto属性值在 CSS  transitions/animations 中是不支持颜色插补(interpolated)的

<color>所指定的插入光标的颜色值.

正式语法

auto | <color>where <color> = <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hex-color> | <named-color> | currentcolor | <deprecated-system-color> where <rgb()> = rgb( [ [ <percentage>{3} | <number>{3} ] [ / <alpha-value> ]? ] | [ [ <percentage>#{3} | <number>#{3} ] , <alpha-value>? ] ) <rgba()> = rgba( [ [ <percentage>{3} | <number>{3} ] [ / <alpha-value> ]? ] | [ [ <percentage>#{3} | <number>#{3} ] , <alpha-value>? ] ) <hsl()> = hsl( [ <hue> <percentage> <percentage> [ / <alpha-value> ]? ] | [ <hue>, <percentage>, <percentage>, <alpha-value>? ] ) <hsla()> = hsla( [ <hue> <percentage> <percentage> [ / <alpha-value> ]? ] | [ <hue>, <percentage>, <percentage>, <alpha-value>? ] ) where <alpha-value> = <number> | <percentage> <hue> = <number> | <angle>

示例

HTML

<input value="This field uses a default caret." /> <input class="custom" value="I have a custom caret color!" />

CSS

input { caret-color: auto; display: block; margin-bottom: .5em; } input.custom { caret-color: red; }

结果

规范

SpecificationStatusComment
CSS Basic User Interface Module Level 3The definition of 'caret-color' in that specification.Candidate RecommendationInitial definition.

浏览器兼容性

FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support57 1No support 253.0 (53.0) 3No support44No support 4 system caret

FeatureAndroid WebviewChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support575753.0 (53.0)No support font color44No support system caret