如何在双击时停止突出显示 div 元素

发布于 2024-11-28 17:30:44 字数 59 浏览 1 评论 0原文

我有一个带有背景图像的 div 元素,我想在双击它时停止在 div 元素上突出显示。有 CSS 属性吗?

I have this div element with a background image and I want to stop highlighting on the div element when double-clicking it. Is there a CSS property for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

千仐 2024-12-05 17:30:44

下面的 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;

向下定位 IE9 并运行 Opera必须使用 HTML 属性 unselectable 来代替:

<div unselectable="on">Test Text</div>

The CSS below stops users from being able to select text. Live example: 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;

To target IE9 downwards and Opera the HTML attribute unselectable must be used instead:

<div unselectable="on">Test Text</div>
静若繁花 2024-12-05 17:30:44

这对我有用

html
{
  -webkit-tap-highlight-color:transparent;
}

This works for me

html
{
  -webkit-tap-highlight-color:transparent;
}
萧瑟寒风 2024-12-05 17:30:44

我试图找到一种解决方案来阻止 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

I was trying to find a solution to stopping div highlighting in Chrome, and turned to this post.
But, unfortunately, none of the answers solved my problem.

After a lot of online research, I found that the fix is something very simple. There is no need for any complex CSS. Just add the following CSS to your web page and you are all set. This works in laptops as well as mobile screens.

div { outline-style:none;}

NOTE: This worked in Chrome Version 44.0.2403.155 m. Also, it is supported in all major browsers of today as explained at this url: https://developer.mozilla.org/en-US/docs/Web/CSS/outline-style

像你 2024-12-05 17:30:44

我不是 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/)。

I'm no CSS expert, but I think you can use tw16's answer as long as you expand the number of elements affected. For instance, this prevents highlighting everywhere on my page without affecting any other kind of interactivity:

*, *:before, *:after {
    -webkit-user-select: none; /* Chrome/Safari */        
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* IE10+ */
}

That first line is courtesy of Paul Irish (via http://adamschwartz.co/magic-of-css/chapters/1-the-box/).

第七度阳光i 2024-12-05 17:30:44

定位所有 div 元素:

div::-moz-selection { background:transparent; }
div::selection { background:transparent; }

定位所有元素:

::-moz-selection { background:transparent; }
::selection { background:transparent; }

Target all div elements:

div::-moz-selection { background:transparent; }
div::selection { background:transparent; }

Target all elements:

::-moz-selection { background:transparent; }
::selection { background:transparent; }
流云如水 2024-12-05 17:30:44

禁用用户选择:

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; }

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;
}

set background transparent for selected element:

div::-moz-selection { background:transparent; }
div::selection { background:transparent; }
迟到的我 2024-12-05 17:30:44

如果某个元素是可点击的,您可能希望将其设为按钮元素。

If an element is clickable, you might want to make it a button element.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文