“user-select: none” and strange behaviour in Firefox

时光毁灭记忆、已成空白 提交于 2019-12-21 09:29:33

问题


I am trying to prevent text highlighting in Firefox for some, but not all elements on the page. Consider the following:

<div style="-moz-user-select: none;">
I cannot be highlighted
    <div  style="-moz-user-select: text;">
    I should be highlightable, but am not.
    </div>
</div>

As I understand it, using the above css rules, the text of the inner div should be highlightable. However this does not appear to work. In practice none of the text can be highlighted.

I am wondering if I am doing something wrong? If not, does anyone know of a workaround for this situation?

Thanks!

ps I should add that using the alternate...

-webkit-user-select: none;

...in the above example works just fine in webkit browsers


回答1:


Replace

<div style="-moz-user-select: none;">

with

<div style="-moz-user-select: -moz-none;">

The description of the -moz-user-select property states that -moz-none means that the text of the element and sub-elements cannot be selected, but selection can be enabled on sub-elements using -moz-user-select: text;




回答2:


Mozilla informs the following about the none property :

The text of the element and sub-elements will appear as if they cannot be selected. Any use of Selection however will contain these elements.

Read -moz-user-select.




回答3:


You may want to try onmousedown="return false" and you can change the cursor if you don't want the selection or pointer with cursor:



来源:https://stackoverflow.com/questions/3077950/user-select-none-and-strange-behaviour-in-firefox

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