开发者

CSS grouping and subgrouping

开发者 https://www.devze.com 2022-12-09 11:27 出处:网络
Is it possible to apply style to all class X only if it\'s of class A开发者_运维知识库, B or C without code duplication?

Is it possible to apply style to all class X only if it's of class A开发者_运维知识库, B or C without code duplication?

I understand grouping:

A, B, C {
   ...
}

But I want something like:

X, (A, B, C) {
   ...
}

How can I achieve this without duplicating code?


Couldn't you do this?

.X.A, .X.B, .X.C {
 /* rules */
}

That will match elements with both class X and A, or X and B, or X and C. Or did I misunderstand your question?


Sorry, I wanted to comment on Marc W's answer, but I guess I don't have enough reputation points to do so >=O

Please note that using multiple classes in a selector, like

.X.A, .X.B, .X.C {
 /* rules */
}

Isn't supported by IE6.


I'm modifying BluePrintCSS to accommodate our needs. Not quite the same as what you're doing, but there is a need to constantly apply styles to bunches of classes or IDs at once just as you are doing.

I've found that it's quicker to built a 'generator' in Javascript and then use that to spit out all the repetitive CSS declarations via nested for loops and such.

The advantage is that when the framework is updated, I can make some tweaks to my script and quickly update my 'over-ride' styles.

0

精彩评论

暂无评论...
验证码 换一张
取 消