网页中当我们选中一段文字时默认颜色为深蓝色。如:
我们有没有办法改成其他颜色。。?答案是有的。。
我们可以通过
CSS ::Selection
来改变。
用法:
::selection使用语法:
/*Webkit,Opera9.5+,Ie9+*/ ::selection { background: 颜色值; color:颜色值; } /*Mozilla Firefox*/ ::-moz-selection { background: 颜色值; color:颜色值; }
兼容的浏览器:
::selection在IE家族中,只有IE9+版本支持,在Firefox中需要加上其前缀“-moz”,查阅相关w3c官方资料,并没有对这个属性的解说资料,只知道这个属性被规纳在CSS的伪类选择器中。
段落中选中任意文本,其背景都是深蓝,前景是白色,下面我们给他加上一个“::selection”运用,把背景改成红色,前景依旧是白色:
p::selection { background: red; color: #fff; } p::-moz-selection { background: red; color: #fff; }
::selection”只能设置两个属性,一个就是background,另一个就是color属性,设置其他属性是没有任何效果的。