有没有办法分组CSS选择器以清楚? [英] Is there a way to group CSS selectors for clarity?

查看:165
本文介绍了有没有办法分组CSS选择器以清楚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有十几个CSS选择器,并且想分配:hover 属性给所有的,我习惯这样做:

If I have a dozen CSS selectors, and want to assign :hover properties to all of them, I'm used to doing this:


selector, selector2, someOtherSelector, someSelector div {
    //some properties
}
selector:hover, selector2:hover, someOtherSelector:hover, someSelector div:hover {
    //some properties
}


键入:hover 四次似乎多余。是否有一种方法来分组选择器像

Typing :hover four times seems redundant. Is there a way to group the selectors like


(selector, selector2, someOtherSelector, someSelector div):hover {
    //some properties
}


instead?

推荐答案

如果它们都共享相同的悬停属性,您可以创建一个为所有定义共享的类your:hover

If they all share the same hover properties you could create a class that is shared for all that defines your :hover

所以你会得到:

allSelectors, selector, selector2, someOtherSelector, someSelector div {
    //some properties
}
allSelectors:hover {
    //some properties
}

可重用类使得代码更干净,代码更少。

Re-usable classes makes for cleaner and less code.

这篇关于有没有办法分组CSS选择器以清楚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆