当前位置: 动力学知识库 > 问答 > 编程问答 >

css - How to reset background color of ::selection

问题描述:

/* Site */

::-webkit-selection {

background-color: @highlightBackground;

color: @highlightColor;

}

::-moz-selection {

background-color: @highlightBackground;

color: @highlightColor;

}

::selection {

background-color: @highlightBackground;

color: @highlightColor;

}

I am using semantic-ui as css framework, and I have been overriding its values today. I came across with selection option, which is overridden by default, and I would like to set it as computer default. As some of you know, you can change selection color in macbooks, so I would like my users to use computer's default selection color.

So, what should I do? I tried inherit and transparent but they don't work.

网友答案:

The solution is to use the system color highlight for the background and highlighttext for the foreground.

Colors like inherit won't work, because inherit means "use the same color as the parent element". That's not what we want!

The first example sets the selection colors to yellow on brown, to emulate the framework theme. Just to make sure changing those colors works at all.

/* colours from theme */
::-webkit-selection {
  background-color: brown; color: yellow;
}
::-moz-selection {
  background-color: brown; color: yellow;
}
::selection {
  background-color: brown; color: yellow;
}
<div>This is a div in which you can make a selection</div>
分享给朋友:
您可能感兴趣的文章:
随机阅读: