简体   繁体   English

忽略特定控件上的CSS声明

[英]Ignore CSS declaration on a specific control

I have a checkbox input control and I have a CSS file which includes the following declaration: 我有一个复选框input控件,并且有一个CSS文件,其中包含以下声明:

input[type="checkbox"] {
    display:none;
}

I want this CSS to be be applied to any checkbox input element except one. 我希望将此CSS应用于除一个以外的任何复选框input元素。 How can I ignore this CSS rule( display:none; ) on one of my controls? 如何在我的一个控件上忽略此CSS规则( display:none; )?

All you need to do is target that specific checkbox and give it a display of initial . 您需要做的只是针对该特定复选框,并为其display initial

You haven't provided any HTML so I'm going to have to make up a generic example: 您尚未提供任何HTML,因此我将不得不组成一个通用示例:

 input[type="checkbox"] { display: none; } input[type="checkbox"].bar { display: initial; } 
 <input type="checkbox" class="foo" /> <input type="checkbox" class="bar" /> <input type="checkbox" class="baz" /> 

You can simply do something like: 您可以简单地执行以下操作:

input[type="checkbox"]:not(.this_one) {
  display: none;
}

Note: Replace this_one with the ID or class of the one you want to exempt(leave out) 注意:将this_one替换为您要豁免的ID或类别(省去)

See working example here 在这里查看工作示例

Just use a class to add this css property (and possibly others) and omit the class for the needed element 只需使用一个类来添加此css属性(可能还有其他属性),然后为所需的元素省略该类

input[type="checkbox"].yourClass 
{
    display:none;
}

  <input type="checkbox" name="vehicle" value="Bike" class = "yourClass"> I have a bike
  <input type="checkbox" name="vehicle" value="Bike" class = "yourClass"> I have a bike
  <input type="checkbox" name="vehicle" value="Bike"> The one without the class

As you can see by the other solutions, there are many ways to accomplish what you want. 从其他解决方案可以看到,有很多方法可以实现所需的目标。 Another way is to use the "cascading" aspect of cascading style sheets by overriding the style within the element: 另一种方法是通过覆盖元素中的样式来使用级联样式表的“级联”方面:

input[type="checkbox"] {
  display: none;
}

<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" style="display:initial" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM