如何在不改变文本颜色的情况下更改光标颜色?

12
我想让我的鼠标光标为#FFF,而我的字体颜色为#000。这是否可能?

1
光标通常是白色的。你确定你指的是“光标”吗? - Devin Burke
6
你是指文本框内的插入符号(caret)吗? - Karl Nicoll
5个回答

11

9

来自mozilla 文档

/* 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);

4

3

更改文本输入框和文本域的光标颜色CSS, 可以使用以下CSS:

input,textarea {
     color: #8f0407;
     text-shadow: 0px 0px 0px #000 ;
     -webkit-text-fill-color: transparent ;
}

input::-webkit-input-placeholder,
     textarea::-webkit-input-placeholder {
     color: #ccc;
     text-shadow: none;
     -webkit-text-fill-color: initial;
}

Codepen演示


1
答案很好。在Chrome中运作良好。但是在Internet Explorer中无法正常工作。 - Jay Ponkia

1
尝试这个。
<style>
input {
  color: rgb(60, 0, 248);  /* change [input cursor color] by this*/
  text-shadow: 0px 0px 0px #D60B0B; /* change [input font] by this*/
  -webkit-text-fill-color: transparent;
}
</style>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接