简体   繁体   English

CSS::选择在 Google Chrome 中不起作用

[英]CSS ::selection not working in Google Chrome

I have this code which works fine in inte.net explorer and Mozilla Firefox but it fails on Google Chrome, this is the basic CSS ::selection selector.我有这段代码在 inte.net explorer 和 Mozilla Firefox 中运行良好,但在 Google Chrome 上却失败了,这是基本的 CSS ::selection器。 Attached is an illustration of the problem:附上问题说明:

Desired result: (IE, Firefox)期望的结果:(IE、Firefox)
在此处输入图像描述

What's wrong: (Chrome)出了什么问题:(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>

::-webkit-selection doesn't seem to fix the issue, but there is another workaround for it: ::-webkit-selection似乎无法解决问题,但是还有另一种解决方法:

 ::-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> 

您应该添加::-webkit-selection

Still wasn't working but this worked for me... 仍然没有用,但这对我有用...

    * {
     -webkit-user-select: text;
     -moz-user-select: text;
     -ms-user-select: text; 
    }

If anyone is still having this issue, check to see you don't have any unspecified :first-letter如果有人仍然遇到此问题,请检查您是否没有任何未指定:first-letter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM