View Full Version : CSS class concat

08-07-2007, 10:13 AM
how do i join 2 classes into a single one?

like say i've got..

.strRed { color:red; }
.bgBlack { background:#000; }

i want to do something like

.Combined strRed bgBlack { border:1px solid orange; }

it will join those 2 classes, and add a border. how do i do that?

08-07-2007, 10:39 AM
You can apply as many classes to one element as you wish:

<div class="strRed bgBlack">Your div</div>

So you could create a class for that border, or to simplify it why don't you just create a new one that has all of the style rules you need, rather than using bits and pieces from other styles to build an element that follows a different style set?

08-07-2007, 10:53 AM
how do i join 2 classes into a single one?To match an element that must have two class names, you would use the code shown below.

.className1.className2 { /* declarations */ }

Do note that this CSS feature is not supported in Internet Explorer 6. My memory is hazy, but I believe that the above rule would match all elements with .className2, regardless of whether or not they are also in .className1, in that browser.

like say i've got..

.strRed { color:red; }
.bgBlack { background:#000; }Presentational class names are bad. If you’re going to do that, you may as well just put the CSS inline with the HTML or not use CSS at all, since you’ll end up having to change both the CSS selector and HTML class attribute every time that you want to change the presentation. Use class names that describe content, not presentation.

08-07-2007, 11:10 AM
i very well know i can do it on the html object, but i want to do it in the CSS.

08-07-2007, 12:46 PM
Join them? Like this or what? :confused:

.newclassname {
color: red;
background: #000;

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum