选择按输入类型标记 [英] Select Label by Input type
问题描述
有没有办法排除或选择标签的输入类型,类似于输入字段?
Is there a way to exclude or select Label by input types, something similar to input field?
label:not([type=checkbox])
label[type=checkbox]
推荐答案
如果你给你的复选框特定的id,请执行以下操作:
If you give your checkboxes specific id's that all start with the same thing, you could do the following:
HTML
<input type="checkbox" id="chkTerms" />
<label for="chkTerms">Read terms & conditions</label>
CSS
label[for*="chk"], label[htmlfor*="chk"]
{
css here
}
可能是现代浏览器。
编辑:我刚刚试过一个小提琴:链接,它的工作原理chrome和IE 8& 9但不是7.我没有尝试在FF。
Probably modern browsers only though. I have just tried a fiddle: link and it works in chrome and IE 8 & 9 but not 7. I did not try it in FF.
EDIT2:只是为了解释这里发生了什么,方括号寻找一个属性称为对于。 asterix将equals的行为从纯平等于改为含有 - 在属性包含chk的地方,它将应用该样式。
Just to give an explanation of what is going on here, the square brackets looks for an attribute called for. The the asterix changes the behaviour of the equals from just a plain equals, to mean contains - wherever the for attribute contains "chk" it will apply that style. You can replace the * with a ^ and it will change it to mean starts with instead of contains.
EDIT3:BoltClock在注释中为IE7提供了一个修复,我已更新答案以包括它。
BoltClock has provided a fix for IE7 in a comment, I have updated the answer to include it.
这篇关于选择按输入类型标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!