Why was ::selection removed from the CSS Selectors spec, and how does its specificity work against type selectors?

前端 未结 4 1556
一个人的身影
一个人的身影 2021-02-08 07:06

Some questions about using CSS to specify the color of selected text:

  1. https://developer.mozilla.org/En/CSS/::selection says that,

    :

4条回答
  •  温柔的废话
    2021-02-08 07:36

    Why was it removed?

    Well that would be a question you would have to ask of the W3C committee that removed it from the draft. My understanding is there has been a lot of internal turmoil within the W3C community since they began writing the HTML5 and CSS3 drafts. Certain individuals that run projects developing the browsers (and I wont go into names) wanted it done one way, and developers be damned. The developer community wanted it done another way, and so began feud over who should control the W3C.

    Given these rules, what would the background color of selected body text be: would it be white, or Highlight?

    Sarfraz hit it on the head here, the :selection pseudo-class will only effect selected text. So in your example when you highlight something the background color changes to Highlight, when it is unselected it returns to white.

    I haven't tested this particular example but here is what I understand of it

提交回复
热议问题