pierallard
pierallard

Reputation: 3371

CSS class inherit from anther class

My question is simple, but I didn't found any documentation about it on Internet. Maybe I didn't search with the right keywords...

Take the example of a CSS class called centered, it centers elements and do some other stuff.

I want to say that all the element of the class news, for example, inherit from centered.

There is several solutions :

I search a code for doing something like this :

.centered { X; Y; Z }
.news { all_the_properties_of_centered; A; B }

then I would declare my news with

<div class="news">...</div>

Is it possible ?

Upvotes: 2

Views: 145

Answers (4)

Nitesh
Nitesh

Reputation: 15749

I suggest to use Emmet, which was previously known as Zen coding for such combinations. It is fast and very productive if constructed logically.

Upvotes: 0

Jan Turoň
Jan Turoň

Reputation: 32912

No. CSS doesn't have anything like extend. However, you can write it this way

.centered, .news { X; Y; Z }
.news { A; B } /* adding rules */

Well, actually it does contain inherit, but it doesn't mean to inherit from another CSS class, but from default element style, see Hanky Panky's comment.

Upvotes: 1

Hanky Panky
Hanky Panky

Reputation: 46900

Simplest way would be

.centered, .news { X; Y; Z }
.news { A; B }

Upvotes: 1

oezi
oezi

Reputation: 51797

you should take a look at LESS CSS (or SASS) which both can do exactly what you want - and offer a lot of other great possibilitys.

Upvotes: 1

Related Questions