关键字: ::selection

为了个性化网站主题,可以对文本高亮背景颜色进行设置。

:selection {
  background: #ffb7b7; /* WebKit/Blink Browsers */
}
::-moz-selection {
  background: #ffb7b7; /* Gecko Browsers */
}


一个简单的例子:



	
	
	
	
	
	
		

This paragragh doesn't use ::selection

This paragragh uses ::selection,highlight color is yellow.

This paragragh uses ::selection,highlight color is blue.



未选中时:

\


选中时:

n块ズ枴浏览器的默认颜色。该3属性在主流浏览器(FF,Chrome)等运行正常。


可在jsfiddle在线编辑里尝试一下:

http://jsfiddle.net/xm7h3oxs/


参考博客:http://css-tricks.com/overriding-the-default-text-selection-color-with-css/