Home  >  Article  >  Web Front-end  >  CSS如何设置选中文本的颜色_html/css_WEB-ITnose

CSS如何设置选中文本的颜色_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:31:231450browse

CSS如何设置选中文本的颜色:
在默认状态选中的文本颜色和背景颜色并不美观,如果能够给句网站整体的配色来设置被选中文本和背景颜色那么将会极大的提高美观度,下面就通过代码实例介绍一下如何实现此效果。
代码如下:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">::selection{  background-color:#84ca7f;  color:#000;}::-webkit-selection{  background-color:#84ca7f;  color:#000;}::-moz-selection{  background-color:#84ca7f;  color:#000;}</style></head><body><div>蚂蚁部落欢迎您,只有奋斗才会有美好的明天</div></body></html>

以上代码当选中文本的时候,能够改变背景色和文本颜色,但是::selection选择符具有浏览器兼容性问题,这里就不多介绍了,具体可以参阅CSS的伪对象选择符::selection一章节。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=9631

更多内容可以参阅:http://www.softwhy.com/divcss/

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn