I want to style the caret of a focused <input type='text'/>
. Specifically, the color and thickness.
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
- Adding a timeout to a render function in ReactJS
It is enough to use color property alongside with -webkit-text-fill-color this way:
Works in WebKit browsers (but not in iOS Safari, where is still used system color for caret) and also in Firefox.
So this means we set text color with text-fill-color and caret color with standard color property. In unsupported browser, caret and text will have same color – color of the caret.
If you are using a webkit browser you can change the color of the caret by following the next CSS snippet. I'm not sure if It's possible to change the format with CSS.
Here is an example: http://jsfiddle.net/8k1k0awb/
'Caret' is the word you are looking for. I do believe though, that it is part of the browsers design, and not within the grasp of css.
However, here is an interesting write up on simulating a caret change using Javascript and CSS http://www.dynamicdrive.com/forums/showthread.php?t=17450 It seems a bit hacky to me, but probably the only way to accomplish the task. The main point of the article is:
HERE is a demo in action
2018 update
There is a new css property
caret-color
which applies to the caret of aninput
orcontenteditable
area. The support is growing but not 100%, and this only affects color, not width or other types of appearance.In CSS3, there is now a native way to do this, without any of the hacks suggested in the existing answers: the
caret-color
property.There are a lot of things you can do to with the caret, as seen below. It can even be animated.
The
caret-color
property is supported from Firefox 55, and Chrome 60. Support is also available in the Safari Technical Preview and in Opera (but not yet in Edge). You can view the current support tables here.Here are some vendors you might me looking for
You can also style different states, such as focus
You can also do certain transitions on it, like