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>
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.
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).
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.
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).
Just tried with background-color: rgba(255,255,255,0.99);
on ::selection
and it works:
http://jsfiddle.net/Hc25u/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With