How to make ::selection background opacity: 1?

2019-06-20 02:50发布

问题:

Is this possible? I want selected text to have a solid background, not a transparent background. opacity: 1 does not do it because there must be a standard override from the browser (or something like that).

::-moz-selection {
  background: #fff;
  color: #000;
}

::selection {
  background: #fff;
  color: #000;
}

body {
  color: #fff;
  font-family: sans-serif;
  line-height: 2em;
}

div {
  padding: 2em;
  background: #F8372A;
  text-align: center;
}
<div>
  <h1>HEY!</h1>
  <p>why is my background not<br/><strong>STARK WHITE</strong><br/>when selected?</p>
</div>

回答1:

Just tried with background-color: rgba(255,255,255,0.99); on ::selection and it works:

http://jsfiddle.net/Hc25u/