为单个输入 ID 定义 CSS 样式,而不是 input[type=checkbox]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18036544/
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
Define CSS style for single input ID, instead of input[type=checkbox]
提问by user2635574
This is my check box
这是我的复选框
<input type="checkbox" name="MyName[]" value="A1" id="A1"/>
<label for="Filter"></label>
<input type="checkbox" name="MyName[]" value="A2" id="A2"/>
<label for="Filter"></label>
This is my style
这是我的风格
input[type=checkbox] {..}
input[type=checkbox] + label {background:'image-1'}
input[type=checkbox]:checked + label {background:'image-2'}
I need to style EACH checkbox with a different checked and unchecked image.
我需要使用不同的选中和未选中的图像来设置每个复选框的样式。
I was thinking to refer to ID instead of input[type=checkbox]
in my CSS.
我想input[type=checkbox]
在我的 CSS 中引用 ID 而不是引用。
How to do that?
怎么做?
回答by Bram Vanroy
回答by Ritabrata Gautam
for
为了
<input type="checkbox" name="MyName[]" value="A1" id="A1"/>
it will be
这将是
input[name=MyName[]] {..}
to satisfy your need
满足您的需要
回答by theftprevention
With the id selector:#
使用id 选择器:#
input#A1 {background:url('image-1.jpg');}
input#A1:checked {background:url('image-1-checked.jpg');}
input#A2 {background:url('image-2.jpg');}