Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make ::selection background opacity: 1?

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>
like image 551
user3479314 Avatar asked Mar 31 '14 00:03

user3479314


People also ask

How do I make background opacity?

Changing the opacity of the background color only To achieve this, use a color value which has an alpha channel—such as rgba. As with opacity , a value of 1 for the alpha channel value makes the color fully opaque. Therefore background-color: rgba(0,0,0,. 5); will set the background color to 50% opacity.

How do I change the background opacity in CSS?

To set the opacity of a background, image, text, or other element, you can use the CSS opacity property. Values for this property range from 0 to 1. If you set the property to 0, the styled element will be completely transparent (ie. invisible).

What is background opacity?

opacity is a CSS property that allows you to change the opaqueness of an element. By default, all elements have a value of 1 . By changing this value closer to 0 , the element will appear more and more transparent. A common use case is using an image as part of the background.

How do I make opacity color in CSS?

In addition to RGB, you can use an RGB color value with an alpha channel (RGBA) - which specifies the opacity for a color. An RGBA color value is specified with: rgba(red, green, blue, alpha). The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque).


1 Answers

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

http://jsfiddle.net/Hc25u/

like image 111
Luigi De Rosa Avatar answered Oct 07 '22 15:10

Luigi De Rosa