kawtousse
kawtousse

Reputation: 4141

attribute a CSS class to a set of check boxes

How to give a set of check boxes a same CSS class. Thanks.

Upvotes: 0

Views: 101

Answers (3)

Quentin
Quentin

Reputation: 943686

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.

Upvotes: 3

Sarfraz
Sarfraz

Reputation: 382776

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>

Upvotes: 3

Kyle
Kyle

Reputation: 67194

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
 }

Upvotes: 1

Related Questions