Thursday, December 10, 2009

CSS – Style Inheritance

I was wondering how I could get style inheritance so that I could derive new styles from an existing style.

Looks like that is not possible (please correct me if I am wrong).

But the next best thing is to realize that you can use multiple styles on an element. The style is applied left to right. This provides a behavior that would be similar to what inheritance would provide me.


.style1 { color:red; }
.style2 { font-weight:bold; }

To apply them both on a DIV:
<div class=”style1 style2”>Hello World</div>

1 comment:

Mio Navman M400 said...

It's really nice tutorial. Thanks for sharing this informative source code with us.