gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 03:14:58 25 4
gpt4 key购买 nike

像这样的问题有很多,我看到的每个答案都是:使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com