2014-01-16 42 views
0

有沒有更緊湊的方式expresss我可以在複雜規範中使用多個CSS類嗎?

dl.class dt em, 
dl.data dt em, 
dl.exception dt em, 
dl.attribute dt em, 
dl.method dt em, 
dl.class dt big, 
dl.data dt big, 
dl.exception dt big, 
dl.attribute dt big, 
dl.method dt big 
{ 
    color: #4f4f4f; 
    font-style: normal; 
} 

例如,像

dl(.class, .data, .exception, .attribute, .method) dt (em, big) { 
    color: #4f4f4f; 
    font-style: normal; 
} 
+1

不符合純粹的CSS。 [Less](http://www.lesscss.org/)和[Sass](http://sass-lang.com/)讓你編寫你的代碼,然後編譯成CSS。 – gilly3

+1

LESS可以做到這一點。 http://blog.slaks.net/2013-09-29/less-css-secrets-of-the-ampersand/ – SLaks

+0

假設你可以定位給定的id或元素中的所有dl,#id dl dt em {}和#id dl dt big {} – Huangism

回答

3

這不可能在CSS的當前版本來完成,但也有在Selectors level 4這種性質的一些建議,它們在一些瀏覽器中被原型化。例如在Firefox中您可以使用:-moz-any這樣的:

:-moz-any(dl.class, dl.data, dl.exception, dl.attribute, dl.method) dt :-moz-any(em, big) 
{ 
    color: #4f4f4f; 
    font-style: normal; 
} 

如何這會工作Here is an example

相關問題