CSS regex selector match one OR another condition?

后端 未结 2 902
有刺的猬
有刺的猬 2021-01-02 04:46

I\'d like to match when /(\\sclassName|^className)/ is satisfied, but when selecting css. Hypothetically I would use like:



        
相关标签:
2条回答
  • 2021-01-02 05:18

    You'll need to use two separate selectors with the same rule. CSS selectors don't really support alternation.

    [class^='icon-'], [class*=' icon-'] {
      /* ... */
    }
    

    div {
      color: red;
    }
    
    [class^='icon-'], [class*=' icon-'] {
      color: green;
    }
    <div class='icon-something another-class'>should match</div>
    <div class='another-class icon-something'>should match</div>
    <div class='another-icon-class another-class'>should not match</div>

    0 讨论(0)
  • 2021-01-02 05:34

    You can use the following selectors to select any element whose class either starts with "icon-" or contains " icon-" (note the space at the start):

    [class^="icon-"], [class*=" icon-"] { ... }
    

    JSFiddle demo.

    0 讨论(0)
提交回复
热议问题