如何禁用双击文本选择,但不是其他? [英] How to disable text selection on double click, but not otherwise?

查看:111
本文介绍了如何禁用双击文本选择,但不是其他?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多问题,像这样一个和每个答案,我看到是:使用用户选择:无



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

解决方案

不太确定我明白你的意思。
你试试这样的东西吗?



在下面的代码段或 codepen DEMO



  :: moz-selection {background:red;} ::  - webkit-selection {background:red;} :: selection {background:red;} a:active ::  -  moz-selection {background:transparent;} a:active ::  - active :: selection,a:focus :: selection {/ * focus + tabindex for ie where where 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。 < / p>  



??


There are tons of questions like this one and every answer I've seen is: use user-select: none. That surprises me, because disabling selection completely is in most cases very bad idea.

I want to disable selection in my HTML5 app, because I use plenty <a> elements without hrefs and when user clicks them fast enough, they get highlighted. That's bad. But I still want them to be able to select their text normally, by holding mouse button down and dragging.

解决方案

not too sure i understand your meaning. are you trying something like this ?

Run the demo in the snippet below or in 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>

??

这篇关于如何禁用双击文本选择,但不是其他?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆