【问题标题】:How can I set a CSS rule to change the selection of all elements, not just text?如何设置 CSS 规则来更改所有元素的选择,而不仅仅是文本?
【发布时间】:2013-09-30 16:15:17
【问题描述】:

这个 CSS 规则……

::selection
{
background-color:#f1f1f1;
}
::-moz-selection
{
background-color:#f1f1f1;
}

…在 Chrome 中产生这种效果:

如您所见,选择的某些部分是默认蓝色。如何使整个选择变为灰色?

【问题讨论】:

    标签: html css selection textselection


    【解决方案1】:

    我使用以下内容来防止选择页面上的所有元素...希望对您有所帮助!

    *{
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    }
    

    【讨论】:

      【解决方案2】:

      -moz-是firefox的前缀

      试试 -webkit- 它适用于 chrome 和 safari

      【讨论】:

      • CSS 正确:WebKit、Opera 和 IE 9+ 支持::selection
      【解决方案3】:

      它必须在另一个<div> 或类似的地方。检查周围设置背景颜色的任何其他地方。如果没有更多代码,我们就无能为力了。

      还可以找到不同的浏览器类型

      -moz-selection
      

      因为那只是火狐。

      【讨论】:

      • CSS 正确:WebKit、Opera 和 IE 9+ 支持::selection
      猜你喜欢
      • 2012-07-11
      • 2015-08-08
      • 2011-03-11
      • 1970-01-01
      • 2017-04-15
      • 1970-01-01
      • 1970-01-01
      • 2018-04-17
      • 1970-01-01
      相关资源
      最近更新 更多