首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >背景颜色输入CSS专用性问题

背景颜色输入CSS专用性问题
EN

Stack Overflow用户
提问于 2021-04-02 08:48:00
回答 2查看 29关注 0票数 0

我正在尝试应用input:read-only样式,但它并没有覆盖input的默认设置,至少在Chrome中是这样。

我已经检查了laws of CSS的优先级(和used this),所有这些都表明只读定义优先。然而,在上图中,您可以看到浏览器没有使用这些样式。

我的代码是

代码语言:javascript
复制
body {
   font-family: 'Helvetica Neue', Helvetica, Arial, 'sans-serif';
   font-size: 14px;
   font-weight: 300;
}
input:read-only {
   background-color: -internal-light-dark(rgb(220, 220, 220), rgb(59, 59, 59)) !important;
   border-color: -internal-light-dark(rgb(118, 118, 118), rgb(133, 133, 133)) !important;
}
input {
   padding: 5px;
   font-weight: 300;
   font-family: 'Helvetica Neue', Helvetica, Arial, 'sans-serif';
   font-size: 14px;
   width: 100%;
}
代码语言:javascript
复制
<input type="text" value='read only text' readonly>
<input type="text">

你知道我错过了什么吗?

EN

回答 2

Stack Overflow用户

发布于 2021-04-02 09:09:18

不要使用Chrome的-内部-亮-暗,尽量使用简单的方式。

代码语言:javascript
复制
input:read-only {
   background-color: rgb(220, 220, 220);
   border-color: rgb(118, 118, 118);
}
代码语言:javascript
复制
<input readonly>

如果它不能正常工作,请尝试在HTML中放入一个类e.g.color以解决特定问题。

代码语言:javascript
复制
.color {
   background-color: rgb(220, 220, 220);
   border-color: rgb(118, 118, 118);
}
代码语言:javascript
复制
<input readonly class="color">

票数 0
EN

Stack Overflow用户

发布于 2021-04-02 12:26:09

请尝试下面提到的代码

代码语言:javascript
复制
body {
   font-family: 'Helvetica Neue', Helvetica, Arial, 'sans-serif';
   font-size: 14px;
   font-weight: 300;
}
input:read-only {
   border-image:linear-gradient(0deg, rgba(118,118,118,1) 0%, rgba(113,113,113,0) 100%);;
  background: linear-gradient(0deg, rgb(220, 220, 220) 0%, rgb(59, 59, 59) 100%);
}
input {
   padding: 5px;
   font-weight: 300;
   font-family: 'Helvetica Neue', Helvetica, Arial, 'sans-serif';
   font-size: 14px;
   width: 50%;
}
代码语言:javascript
复制
<input type="text" readonly>
<input type="text">

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66913211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档