使用CSS更改文本选择颜色? [英] Changing the text selection color using CSS?

查看:189
本文介绍了使用CSS更改文本选择颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在网站上工作,我想更改文字选择颜色。

I'm currently working on a website, and I want to change the text selection color.

我有一些工作。这是我的样式表中的代码的一部分:

I have it somewhat working. This is (part of) the code in my stylesheet:

::selection {
  background: #FF0099;
  color: black;
  text-shadow: none;
}

::-moz-selection {
  background: #FF0099;
  color: black;
  text-shadow: none;
}

它产生了最令人满意的结果。但是,在某些情况下,突出显示似乎失去其给定的颜色(#FF099),如下图所示:

It produces a mostly satisfying result. However, in some cases, the highlighting seems to lose its given color (of #FF099), as shown in this picture:

如上图所示,正确的颜色(#FF099);然而,主体文本和标题之间的区域以及主体文本的左侧用默认颜色(蓝色)突出显示。如何保持突出显示的某些部分不会回到默认值?

As you can see in the picture above, the text is entirely highlighted using the correct color (#FF099); however, the area between the body text and the title, as well as to the left of the body text, is highlighted with the default color (of blue). How can I keep parts of the highlighting from going back to the default?

编辑: http://i.imgur.com/NmZIf.png

编辑:jsFiddle sample: a href =http://jsfiddle.net/VUuFR/ =nofollow noreferrer> http://jsfiddle.net/VUuFR/

edit: jsFiddle sample: http://jsfiddle.net/VUuFR/

推荐答案

我之前已经解决了这个问题,结果是:

I have wandered upon this problem before and it turns out:

::selection (or whatever selection you might use)

删除它们并使用边距。 =)这里是一个小提琴演示:示例

does not work on an break line tag (br).. remove them and use margins instead. =) Here is an fiddle to demonstrate: Example

这篇关于使用CSS更改文本选择颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆