Html 我们可以在css中将两个规则合并为一个规则吗?

Html 我们可以在css中将两个规则合并为一个规则吗?,html,jquery,css,flexbox,Html,Jquery,Css,Flexbox,我有两个senario类,分别从icn-和betwenicn-开始。它们都有相同的属性。我们可以添加一个选择器或regex,在这两种情况下都有效吗 .f20 [class^="icn-"]:before,.f20 [class*=" icn-"]:before { font-family: 'icons' !important; speak: none; font-style: no

我有两个
senario
类,分别从
icn-
和betwen
icn-
开始。它们都有相同的属性。我们可以添加一个选择器或
regex
,在这两种情况下都有效吗

 .f20 [class^="icn-"]:before,.f20 [class*=" icn-"]:before {
            font-family: 'icons' !important;
            speak: none;
            font-style: normal;
            font-weight: normal;
            font-variant: normal;
            text-transform: none;
            line-height: 1;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale
        }

在您的情况下,您可以编写以下内容:

.f20 [class*="icn-"]:before {
   color: pink; /*whatever you want goes here*/
}

这将选择任何
icn-
类(如果它在开头或其他地方)。注意,这也会选择类似于
此icn类的内容,因为它只检查
icn-
,不关心前面是什么字符。

为什么
icn
不是类?可以基于多个类进行选择。编辑:例如,如果您将
icn whatever
分为两类
icn
whatever
,那么您可以将
.icn whatever
放在
.icn.whatever
的位置(注意不要空格)。当然,这将允许您在需要时单独选择
.icn
。这是相关的: