我有一个带有背景图片的div元素,我想在双击它时停止高亮它。 是否有CSS属性可以实现这一点?
这个问题可以通过CSS属性user-select来解决。将其设置为none可以防止元素被选中。
示例代码:
div {
background-image: url('example.jpg');
user-select: none;
}
我有一个带有背景图片的div元素,我想在双击它时停止高亮它。 是否有CSS属性可以实现这一点?
这个问题可以通过CSS属性user-select来解决。将其设置为none可以防止元素被选中。
示例代码:
div {
background-image: url('example.jpg');
user-select: none;
}
以下的 CSS 代码可以防止用户选择文本。实时示例:http://jsfiddle.net/hGTwu/20/
/* If you want to implement it in very old browser-versions */
-webkit-user-select: none; /* Chrome/Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+ */
/* The rule below is not implemented in browsers yet */
-o-user-select: none;
/* The rule below is implemented in most browsers by now */
user-select: none;
unselectable
。<div unselectable="on">Test Text</div>
@include user-select(none);
代替使用原始CSS。 - hilniusdraggable = false
的情况下也能在Firefox上拖动。 - rovyko这对我有效
html
{
-webkit-tap-highlight-color:transparent;
}
我试图找到在Chrome中停止div高亮的解决方案,并转向了这篇帖子。但不幸的是,没有一个答案解决了我的问题。
在进行了大量在线研究后,我发现解决方法非常简单。不需要任何复杂的CSS。只需将以下CSS添加到您的网页中即可。这适用于笔记本电脑和移动屏幕。
div { outline-style:none;}
注意:这在Chrome 44.0.2403.155 m版本中有效。同时,如此解释的那样,它支持当今所有主流浏览器,详情请看此链接:https://developer.mozilla.org/en-US/docs/Web/CSS/outline-style
我不是CSS专家,但我认为您可以使用tw16的答案,只要您扩大受影响元素的数量。例如,这可以防止在我的页面上到处突出显示而不影响任何其他类型的交互:
*, *:before, *:after {
-webkit-user-select: none; /* Chrome/Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+ */
}
这句话是出自Paul Irish之手的(通过http://adamschwartz.co/magic-of-css/chapters/1-the-box/)。
div::-moz-selection { background:transparent; }
div::selection { background:transparent; }
::-moz-selection { background:transparent; }
::selection { background:transparent; }
disable user selecting:
div {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
为选定元素设置透明背景:
div::-moz-selection { background:transparent; }
div::selection { background:transparent; }