【问题标题】:How to change label color of disabled checkbox in ASP.NET?如何在 ASP.NET 中更改禁用复选框的标签颜色?
【发布时间】:2013-03-22 10:26:56
【问题描述】:

如何通过 CSS 更改 asp 控件的禁用复选框标签。检查已禁用,但即使我尝试通过 CSS,标签颜色也没有改变,所以 CSS 有任何线索或提示吗?

【问题讨论】:

  • 可以使用 Jquery addclass 属性
  • 如何禁用复选框?通过属性 enabled=false 或 disabled="yes" ?在以后的情况下,禁用的控件不会在 IE 上显示颜色
  • 感谢 Ramesh Rajendran 和 Manish Mishra,@Anh Tú 回答解决了我的问题...谢谢大家的帮助!

标签: asp.net css checkbox controls


【解决方案1】:

使用加号 (+) 获取相邻元素 (http://www.w3.org/TR/CSS21/selector.html#adjacent-selectors)

input[type="checkbox"]:checked+label{ font-weight: bold; }

input[type="checkbox"]:disabled+label
{
     color:#ccc;
}

【讨论】:

  • 我们无法访问复选框中的禁用属性。他只想更改启用复选框时的标签颜色。所以你的两个解决方案都不起作用。
【解决方案2】:

试试下面的方法

<div>
  <input type="checkbox" class="check-with-label" />
  <label class="label-for-check">My Label</label>
<div>


.check-with-label:Enabled + .label-for-check {
  font-weight: bold;
  color:red;
}

看到这个checked design

更多讨论

How to change color of checkbox label while toggling checked/unchecked state on click

Change label when checkbox is checked

【讨论】:

【解决方案3】:

你可以这样使用

ListItem li = new ListItem("Richard Byrd", "11");
li.Selected = false;
li.Attributes.Add("Style", "color: red;");
CheckBoxList1.Items.Add(li);

或者您可以像这样使用标签,因为标签在td 中呈现,所以下面可以是一个解决方案

样式.css

.chkboxlist td 
{
    color:red;
}

页面.aspx

<asp:CheckBoxList ID="chkboxlist1" runat="server" CssClass="chkboxlist" />

【讨论】:

  • 谢谢@Shekhar,问题解决了: input[type="checkbox"]:checked+label{ font-weight: bold; } 输入[type="checkbox"]:disabled+label { 颜色:#ccc; } 加号 (+) 获取相邻元素 (w3.org/TR/CSS21/selector.html#adjacent-selectors)
猜你喜欢
  • 2021-08-18
  • 2020-08-29
  • 2015-01-05
  • 2021-02-14
  • 2021-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-16
相关资源
最近更新 更多