Firefox ::-moz-selection selector bug(?) is there a workaround?

前端 未结 1 375
独厮守ぢ
独厮守ぢ 2020-12-04 03:06

I\'m working on a site that has a large number of color styles, around 250 lines of CSS to define one of 7 color schemes, so it\'s important that I keep the various color ru

相关标签:
1条回答
  • 2020-12-04 03:26

    Firefox appears to simply not understand ::selection (hence necessitating the vendor-prefixed ::-moz-selection), so it ignores the entire rule on encountering an unrecognized selector per the spec.

    The common workaround for a browser not understanding one or more selectors in a group is to split/duplicate the rule set:

    /* Firefox sees this */
    .green ::-moz-selection {
        background-color: #62BA21;
        color: white;
    }
    
    /* Other browsers see this */
    .green ::selection {
        background-color: #62BA21;
        color: white;
    }
    

    In fact, in this case it's the only thing you can do, i.e. you will have to put up with this slight bit of bloat.

    jsFiddle demo

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