Html 如何从输入元素中删除插入符号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23515754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:43:10  来源:igfitidea点击:

How to remove the caret from an input element

htmlcssinput

提问by Rafa Romero

How can I remove the caret from a <input type="text">element only using CSS and not JavaScript?

如何<input type="text">仅使用 CSS 而不是 JavaScript从元素中删除插入符号 ?

回答by Rafa Romero

Of course you can do it just with CSS.

当然,您可以仅使用CSS.

Add this code to your CSS file:

将此代码添加到您的 CSS 文件中:

border: none;
color: transparent;
text-shadow: 0 0 0 gray;
text-align: center;

&:focus {
    outline: none;
}

Here you have the SOURCEand a DEMO

在这里你有源演示

回答by Rakesh Shetty

I can only say you that you can achieve this by applying the color through css :

我只能说你可以通过 css 应用颜色来实现这一点:

<input type="text" style="color: transparent;text-shadow: 0 0 0 red;" />

FIDDLE DEMO

小提琴演示

Otherwise there is no way to style the text cursor with CSS.

否则无法使用 CSS 设置文本光标的样式。