css - 使用 css 选择器禁用与复选框关联的标签

标签 css html css-selectors

我想禁用与复选框关联的标签。代码片段如下:

代码:

<label for="label1" class="form-checkbox-left"><input type="checkbox" name="labelname" id="label1" value="0" style="min-width: 20px;" disabled>Name 1</label>

CSS : .form-checkbox-left input[type=checkbox]:disabled { 颜色:#ccc; }

不知何故它不起作用。

请帮忙

最佳答案

您可以选择使用 element+element选择器。但是,您需要将输入放在标签之前

input[type=checkbox]:disabled+label {
  color: #ccc;
}
<input type="checkbox" name="labelname" id="label1" value="0" style="min-width: 20px;" disabled>
<label for="label1" class="form-checkbox-left">Name 1</label>

关于css - 使用 css 选择器禁用与复选框关联的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52084585/

相关文章:

java - 在Servlet中获取表单值

javascript - 使用 Rails 事件记录关联创建 JavaScript 变量

html - Chrome 21 上的单选按钮白色背景、flash 对象和 iFame

html - CSS 规则中第 n 个 child 的索引?

html - 图片作为要点

html - CSS 计数器 : doesn't reset if there is a wrapper outside OL

html - 如何在 Bootstrap 中的卡之间添加填充

css - SP2010 QuickLaunch 被 head 标签之间的 css 规则隐藏 - 我不想要这个

html - 选择 <p> 标签后的所有 <h2>

php - CSS 为列表中的最后一个子项设置样式