What is the browser-default background color when selecting text?

后端 未结 3 503
天涯浪人
天涯浪人 2020-12-01 10:35

When you select text in a webpage, the background gets a default blue color. What exact color code does this blue color have?

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 10:55

    The ::selection CSS pseudo-element applies rules to the portion of a document that has been highlighted (e.g., selected with the mouse or another pointing device) by the user.

    The default depends on the browser you are using. It's usually somewhere around #3297fd.

    You can change it like so:

    /* draw any selected text yellow on red background */
    ::-moz-selection { color: gold;  background: red; }
    ::selection      { color: gold;  background: red; } 
    
    /* draw selected text in a paragraph white on black */
    p::-moz-selection { color: white;  background: black; }
    p::selection      { color: white;  background: black; }
    

提交回复
热议问题