Interview Questions

I always wanted to have "included" substyles or "aliases" in my CSS definition, to save redundancy ...

CSS Interview Questions and Questions


(Continued from previous question...)

56. I always wanted to have "included" substyles or "aliases" in my CSS definition, to save redundancy ...

I always wanted to have "included" substyles or "aliases" in my CSS definition, to save redundancy.

(For includes)

.class1 { color:#ff0000; }
.class2 { background-color:#ffffff; }
.class3 { include:class1,class2;font-weight:bold; }

(For aliases)

@alias color1 #ff0000;
@alias color2 #ffffff;
@alias default_image url('/img/image1.jpg');

.class1 { color:color1; }
.class2 { background-image:default_image;background-color:co lor2; }

This way we could change colors or images for a whole webpage
by editing a reduced number of lines.
Had you considered any of these ideas in the past? If so, why were they rejected?


Yes, aliases and constants have been considered. CSS is already an indirection. Instead of putting properties and values directly on elements, it associates properties and values with selectors. What you (and others) are proposing is to add another layer of indirection. By doing so, one could possible write shorter, more manageable style sheets. However, there are also some downsides. It requires a new syntactic construct (@alias) and implementations must be able to remember a list of aliases. What if aliases are defined in one style sheet and referenced in another -- should that work? If so, what if the first style sheet isn't available?....

(Continued on next question...)

Other Interview Questions