I have this code which works fine in internet explorer and Mozilla Firefox but it fails on Google Chrome, this is the basic CSS ::selection
selector.
Attached is an illustration of the problem:
Desired result: (IE, Firefox)
What's wrong: (Chrome)
This only happens in Google Chrome, I am attaching the code I've tried here:
::-moz-selection {
background-color: orange;
color: white;
}
::selection {
background-color: orange;
color: white;
}
::-webkit-selection {
background-color: orange;
color: white;
}
<ol>
<li>Hello World!</li>
<li>What's up?</li>
</ol>
Make sure that your CSS and HTM/HTML files use the same encoding ! If your HTM/HTML files are encoded as UNICODE, your stylesheet has to be as well. IE and Edge are not fussy : stylesheets are rendered regardless of the encodings. But Chrome is totally intolerant of unmatched encodings.
Enabling support for the :has() selectorMake sure you have Chrome 101+ and navigate to chrome://flags from the browser's address bar. Set the Experimental Web Platform features to Enabled and you're good to go. Relaunch the browser and you can work with CSS :has() in your Chrome browser.
::-webkit-selection
doesn't seem to fix the issue, but there is another workaround for it:
::-moz-selection {
background-color: orange;
color: white;
}
::selection {
background-color: orange;
color: white;
}
ol {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
ol span {
-webkit-user-select: all;
-moz-user-select: all;
-ms-user-select: all;
}
<ol>
<li><span>Hello World!</span></li>
<li><span>What's up?</span></li>
</ol>
You should add ::-webkit-selection
Still wasn't working but this worked for me...
* {
-webkit-user-select: text;
-moz-user-select: text;
-ms-user-select: text;
}
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