如何更改选择背景颜色 [英] how to change the selecting background color

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

问题描述

我的意思是:当你选择一些html文本时,在背景中有一种颜色,它告诉你所选择的文本,它是如何可能通过CSS改变它,我需要它是白色,透明的。我看到这样做了。
cheers

I mean: when you select some html text there's a color in the background wich tells you wich text you've selected, how is it possible thru css to change it, i need it to be white , transparent. i' have seen this done. cheers

推荐答案

您可以使用某些CSS选择器来更改所选文本的CSS属性。 (我测试了这一点,它工作在Firefox,Safari,Chrome,甚至Konqueror,但不是IE)。示例:

You can use certain CSS selectors to change CSS properties on selected text. (I tested this and it worked in Firefox, Safari, Chrome, and even Konqueror, but not IE). Example:

*::selection {
    background: #cc0000;
    color: #ffffff;
}
*::-moz-selection {
    background: #cc0000;
    color: #ffffff;
}
*::-webkit-selection {
    background: #cc0000;
    color: #ffffff;
}

您必须单独指定每个选择器,否则它不工作猜测CSS解析器停止处理选择器,如果它遇到错误)。这将所选文本的背景颜色更改为深红色,将颜色更改为白色(以及您要更改的任何其他CSS)。这没有伟大的跨浏览器支持(不工作在IE,可能不是Opera,或者),但我认为这是唯一的解决方案可能没有一些复杂,buggy JavaScript脚本。

You have to specify each selector separately or else it doesn't work (I guess the CSS parser stops processing a selector if it encounters an error). This changes the background color of the selected text to dark red and the color to white (and any other CSS you want to change). This doesn't have great cross-browser support (doesn't work in IE, and probably not Opera, either), but I think it is the only solution possible without some kind of complicated, buggy JavaScript script.

更多信息: http://www.quirksmode.org /css/selection.html

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

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