How to give a set 开发者_高级运维of check boxes a same CSS class. Thanks.
Apply same class name to all of them:
<input tyep="radio" class="myclass" name="whatever" />
<input tyep="radio" class="myclass" name="whatever" />
<input tyep="radio" class="myclass" name="whatever" />
CSS:
<style type="text/css">
.myclass
{
color:#ff0000;
}
</style>
There is no such thing as "A CSS Class". CSS has rule sets, selectors (including a class selector) and properties, but not classes. These are an HTML concept.
If you mean "An HTML Class" then just add a class attribute with the same value to each checkbox:
<input … class="foo">
<input … class="foo">
<input … class="foo">
If you mean "Write a selector that matches a set of checkboxes" then use attribute selectors:
input[type=checkbox][name=checkboxGroupName] { /* … */ }
You can leave the first attribute selector out if there is no other kind of input with the same name. You can leave the second attribute selector out if you want to match all checkboxes and not just those in a particular group.
Note that IE6 does not support attribute selectors, and other versions of IE may not support them in Quirks mode. If this is an issue, modify your markup instead and use a selector that is supported.
You should just assign the same class to your checkboxes:
<input type="checkbox" class="yourclass" value="1">
<input type="checkbox" class="yourclass" value="1">
.yourclass
{
your styles here
}
Classes are designed to be assigned to multiple elements, unlike the id attribute which must be unique within a page.
<input type="checkbox" id="unique" value="1">
#unique
{
different styles
}
精彩评论