Log in

View Full Version : Two Classes in one



dude9er
05-07-2008, 04:07 PM
I have multiple classes that share the same style except one, the width. Is it possible to set one class for the shared styles and call it within the width class?

Here's an example:

Shared style:



.inputElements {
background-color:white !important;
background-image:url(txtBoxBG2.gif);
background-repeat:repeat-x;
border:1px solid #9A9B8D;
color:#5D5E4E;
font-family:Arial,Helvetica,sans-serif;
font-size:12px;
font-weight:normal;
height:22px;
margin-bottom:5px;
margin-top:2px;
text-align:center;
}




Width class



.inputTblRmBl {
width:40px;
}


I want to call them both at the same time, something like this (which doesn't work)




.inputTblRmBl , .inputElements {
width:40px;
}



Any suggestions?

Thanks in advance!!!

dude9er
05-07-2008, 04:16 PM
making it an easier question, can one css class call another?

Medyman
05-07-2008, 10:43 PM
I thought I knew what you were asking when I started reading your post but I'm confused now. Let me give it a shot anyway.

You can call two classes in your HTML. It's quite simple.


.green {
color:green;
border:1px solid black;
}

.noborder {
border:0;
}


<p class="green noborder">This is green text with no border</p>
<p class="green">This is green text with a border</p>

Notice the order that I added the classes in. The CSS cascade is valid in the declerations as well. So, class="noborder green" would have a border because the second class (green) will override the border decleration of noborder. The opposite is also true. Class="green noborder" shows no border because the 2nd called noborder class overwrites the green class.

The same principle applies even if you're not overwriting anything. To combine class attributes, just call both classes.

I hope that helps. If not, please clarify what you're trying to do a little more.