简体   繁体   English

带有选择器列表的css:not()选择器

[英]css :not() selector with selector list incoming

I have many css selectors and many selector exception, so I use :not to leave them out... 我有很多CSS选择器和许多选择器异常,所以我使用:not可以将它们排除在外...

example (just some selectors I don't need): 示例(只是一些我不需要的选择器):

[class*="-dashboard-"]:not([class$="-binding"]), [class*="-dashboard "]:not([class$="-binding"]), [class$="-dashboard"]:not([class$="-binding"])

But what I instead would prefer is: 但是我宁愿选择的是:

([class*="-dashboard-"],[class*="-dashboard "],[class$="-dashboard"]):not([class*="-binding-"],[class*="-binding "],[class$="-binding"])

or something else, that ist shorter than the working one and easier to edit and not so repetitive... 或其他一些东西,它比工作中的那个更短,并且更容易编辑,并且没有那么重复...

My problem is that I have that selectors in big list. 我的问题是我的选择器很大。 The user is allowed to add/remove lists so I have to dynamically change the selectors and exceptions. 允许用户添加/删除列表,因此我必须动态更改选择器和异常。

Does anybody have an idea to short that one??? 有人有做空的想法吗???

Usually, the way my CSS looks is with increasing specificity. 通常,我的CSS外观具有越来越高的特异性。 A very generic rule sets a whole lot of defaults, and then something that positively matches one of those rules you gave us overrides that style with something else. 一个非常通用的规则会设置很多默认值,然后某些与您给我们提供的规则中的一个肯定匹配的规则会以其他方式覆盖该样式。

For instance, you could set a higher-priority rule for anything ending in "-binding" that makes elements invisible, or whatever you intend for them. 例如,您可以为任何使元素不可见的以“ -binding”结尾的事物设置更高优先级的规则。 In simple terms, to calculate a CSS rule's priority: 简单来说,要计算CSS规则的优先级:

  • Add 100 for each ID selector 每个ID选择器加100
  • Add 10 for each class selector 为每个类选择器添加10
  • Add 1 for each other selector 彼此加1

I think you'd do well by having more classes in your elements that are easily selected, ie anything that adds a lolwtf-dashboard class should also add a dashboard class that's easily CSS-selected. 我认为您可以通过在元素中轻松选择更多类来做得很好,例如,添加lolwtf-dashboard类的任何内容也应该添加易于CSS选择的dashboard类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM