Unfortunately you cannot do this in pure CSS, by default the child never inherits width , you need to specify it, yes, by default it will span 100% if you use a block level element like div or p , but inorder to inherit (re use) property grand parent you can use CSS preprocessors such as LESS or SASS ..
So, if you want to do this in SASS, we can do something like
.a { width: 600px; } .b { width: 80%; } .c { @extend .a; //This is still not an inheritance, you are simply pulling in all the //properties defined in .a to this class }
So, here he selects all the properties from .a to .c . But here's the trick when you use notation . in SASS, it literally prints the .a block, so if you want to use it only for @extend , you can write this selector instead
%a { width: 600px; } .c { @extend %a; }
Here, SASS no longer prints .a , but only .c . You can link to white papers for more SASS @extend
You can also define variables in SASS, so the definition is with $base-width: 600px; and reusing it through may make sense. If you still want to stick with traditional CSS, I would recommend that you declare several classes in the same way as Manoj suggested, but I would not do this as if you were declaring any properties in .a and the same in .c , everything will start to get confused.
Mr. Alien
source share