css - 如何禁用双击时的文本选择,但不禁用?

标签 css html selection double-click

像这样的问题有很多,我看到的每个答案都是:使用 user-select: none .这让我感到惊讶,因为在大多数情况下完全禁用选择是非常糟糕的主意。

我想在我的 HTML5 应用程序中禁用选择,因为我使用了很多 <a>没有 hrefs 的元素,当用户足够快地点击它们时,它们会突出显示。那很糟。但我仍然希望他们能够通过按住鼠标按钮并拖动来正常选择文本。

最佳答案

不太确定我理解你的意思。 你在尝试这样的事情吗?

在下面的代码片段或 codepen DEMO 中运行演示

::-moz-selection {
  background: red;
}
::-webkit-selection {
  background: red;
}

::selection {
  background: red;
}
a:active::-moz-selection {
  background: transparent;
}
a:active::-webkit-selection {
  background: transparent;
}

a:active::selection , a:focus::selection{/* focus + tabindex for ie where no href*/
  background: transparent;
}
a {border:solid;}
<p>Pellentesque <a>habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas</a>. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit <a tabindex="0">Internet Explorer</a>amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>

??

关于css - 如何禁用双击时的文本选择,但不禁用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28664376/

相关文章:

html - 使固定位置元素不超过屏幕上的某个阈值

html - CSS - 带有切 Angular 和边框颜色的矩形 div

javascript - 确定选择是否存在

javascript - 将光标移动到 contentEditable DIV 中的占位符元素

html - CSS3后台查询

html - 背景尺寸封面仅适用于内联样式的移动设备

html - 使用 css 和 HTML 排列 div

html - X3D计算IndexedFaceSet coordIndex

python - 选择排序的重复问题

php - 粘贴到 Skype 或其他社交媒体时如何在文本中显示公共(public)图像