How to disable text selection on double click, but not otherwise?

巧了我就是萌 提交于 2019-12-06 05:07:33

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>

??

I have a basic scripting solution. Check out this JSFiddle. Basically, what I've done is store and restore selectionStart and selectionEnd values based off of Javascript events. I simplified it a lot since the base version. It should work perfectly for disabling text selection on double-clicks.

There's no real way to do this in CSS that I've thought of so far.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!