Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css class within another class as a property

Tags:

css

I'm wanting to use properties from other css classes without having to rewrite the code...I'm not too savvy with css so please forgive me for the simple question.

Is it possible to do something like this or similar to it in css?

.class_a {
    background:red;
}

.class_b{
    .class_a;
}
like image 239
Ronedog Avatar asked Sep 11 '10 22:09

Ronedog


2 Answers

The best way (that I know of) to re-use css classes is to decide on the css attributes you want to re-use, and put this in a seperate class, like so:

.class_a {
    background:red;
}

Then, every time you want to re-use these attributes, you add the class to the html element, with spaces in between different class names, like so:

<div class="text class_a">This will be red, and have the properties of the text class</div>
<div class="text">This will only have the properties of the text class</div>
like image 79
Herman Schaaf Avatar answered Sep 29 '22 12:09

Herman Schaaf


You can use the same property list for more than one selector:

.class_a, .class_b {
    background:red;
}
like image 32
aularon Avatar answered Sep 29 '22 12:09

aularon