开发者

attribute a CSS class to a set of check boxes

开发者 https://www.devze.com 2022-12-29 06:16 出处:网络
How to give a set 开发者_高级运维of check boxes a sameCSS class. Thanks. Apply same class name to all of them:

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
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消