html 中禁用的文本框使用什么颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16176346/
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 07:48:09  来源:igfitidea点击:

What color do disabled text-boxes in html uses?

htmlcsscolors

提问by ssBarBee

my question says it all. I'm interested in the text color and the background color that disabled text-boxes in HTML use ( the entire CSS a disabled text-box use is also welcomed ). I need this so I would match the color settings of some readonly text-boxes with the color of disabled text-boxes in my html page ( don't want them to stick out ).

我的问题说明了一切。我对在 HTML 中禁用文本框的文本颜色和背景颜色感兴趣(也欢迎使用整个 CSS 禁用文本框)。我需要这个,所以我会将一些只读文本框的颜色设置与我的 html 页面中禁用文本框的颜色相匹配(不希望它们突出)。

P.S. I need readonly text-boxes so I can capture events with them.

PS 我需要只读文本框,以便我可以用它们捕获事件。

回答by Kenneth

The background color is rgb(235, 235, 228);or #EBEBE4in hex.

背景颜色是rgb(235, 235, 228);#EBEBE4十六进制。

At least that's the value in chrome (checked with the debugger tools). This value could be different in other browser

至少这是 chrome 中的值(用调试器工具检查)。此值在其他浏览器中可能不同

回答by Niet the Dark Absol

They are whatever you set them to. Only IE9 and older have a fixed, unchangeable setup for disabled elements (which is oddly the only way you can get any kind of text-shadowin those versions...)

他们是你设置的任何东西。只有 IE9 及更早版本对禁用元素有固定的、不可更改的设置(奇怪的是,这是您可以text-shadow在这些版本中获得任何类型的唯一方法......)

You can literally do this:

你可以从字面上做到这一点:

:disabled {background-color:pink; color:blue}

And get bubblegum-coloured textareas when you disable them!

当你禁用它们时,得到泡泡糖​​色的文本区域!

What I'm trying to say is that you can set the styles to whatever you want, so you could do this:

我想说的是,您可以将样式设置为您想要的任何样式,因此您可以这样做:

:disabled, :read-only, [disabled], [readonly] {background:#cccccc; color:#ffffff}

回答by EGC

I implemented the following to make any read-only textbox or textarea (useful in my case) appear disabled when it was readonly.

我实现了以下内容以使任何只读文本框或文本区域(在我的情况下有用)在只读时显示为禁用。

<style>
input:read-only, 
textarea:read-only,
[contenteditable]:read-only {
  cursor: not-allowed;
  background-color: #EBEBE4 !important;
  color: #C6C6C6;
} 
</style>

Or this:

或这个:

<style>
input:read-only, 
textarea:read-only,
[contenteditable]:read-only {
  pointer-events: none;
  background-color: #EBEBE4 !important;
  color: #C6C6C6;
}
</style>

Hopefully this helps someone!

希望这对某人有所帮助!

回答by Gibas

It depends on the browser. In Chrome, it is the system color 'graytext', so you don't need to remember the hex code.

这取决于浏览器。在 Chrome 中,它是系统颜色 'graytext',所以你不需要记住十六进制代码。

回答by Magnus Lindgren

My chrome has the following default:

我的 chrome 具有以下默认值:

background-color: rgb(235, 235, 228);
color: rgb(84, 84, 84);

I guess it can change with browser though?

我想它可以随浏览器改变吗?