更改选择的颜色
问题描述:
当您在浏览器中选择文字时,大多数情况下背景背后的文字会变为蓝色。如何将此颜色更改为另一种颜色?
When you select text in browser, most often background behind text being selected changes color to blue. How to change this color to another?
答
您正在查找 c>伪元素。
You are looking for the selection
pseudo-element.
::-moz-selection{ background: #000; color:#fff;}
::selection { background:#000; color:#fff; }
另外,如果你打算在你的网站使用文本阴影,我建议添加 text-shadow:none;
到你的 :: selection
样式。正如您可以在这个小提示中看到的,它真的很难在眼睛。
Also, as a side note. If you plan on using text-shadow in your site at all, I would recommend adding text-shadow:none;
to your ::selection
styling. As you can see in this fiddle, it is really hard on the eyes.