Reputation: 1527
I'm looking for some trick(s) to make style inherited from another object/class/id. Simple trick: use classes, but are there another ways to specify style of another rule?
Sorry for explanation.. I'm looking for something like:
.st1 {font-size:17pt;} .st2 {-moz/ms/webkit-extends: '.st1';}
?
Actually, I'm not really looking for it (because I use classes), just interested in.
Upvotes: 1
Views: 94
Reputation: 79031
Rather than searching for tricks, You are looking for CSS extension libraries like
They do not exactly give a way to do it like you want, but provide even better one. Like
.st1 {font-size:17pt;}
.st2 {
.st1;
}
When the website is launched, these style declarations are compiled and optimized into a valid CSS document.
Upvotes: 2
Reputation: 11774
With pure CSS, no
But if I understand you right:
I think you can try JavaScript to find every object with class Y and prepend the class X
Something like:
//disclaimer: I haven't tested it
var objs=document.getElementsByTagName('*');//getElementsByClassName, not very crossbrowser
for(var i=0,len=objs.length;i<len;i++){
var temp=objs[i].className;
if((" "+temp+" ").indexOf(" classY ")==-1){//spaces are important
objs[i].className="classX "+temp;
}
}
Upvotes: 0
Reputation: 16263
CSS inheritance relays on the DOM structure, so unless the involved elements are having a descendant / ancestor relationship, no, CSS offers no such functionality.
you can, regardless, use libraries like LessCSS to implement template-like placeholders for property values, thereby turning your CSS into a dynamic stylesheet.
Upvotes: 0