叼花硬汉 2009-05-05 20:29 采纳率: 0%
浏览 342

如何禁用文本选择突出显示?

For anchors that act like buttons (for example, Questions, Tags, Users, etc. at the top of the Stack Overflow page) or tabs, is there a CSS standard way to disable the highlighting effect if the user accidentally selects the text?

I realize this could be done with JavaScript, and a little googling yielded the Mozilla-only -moz-user-select option.

Is there a standard-compliant way to accomplish this with CSS, and if not, what is the "best practice" approach?

转载于:https://stackoverflow.com/questions/826782/how-to-disable-text-selection-highlighting

  • 写回答

29条回答 默认 最新

  • from.. 2009-05-05 20:37
    关注

    Until CSS 3's user-select property becomes available, Gecko-based browsers support the -moz-user-select property you already found. WebKit and Blink-based browsers support the -webkit-user-select property.

    This of course is not supported in browsers that do not use the Gecko rendering engine.

    There is no "standards" compliant quick-and-easy way to do it; using JavaScript is an option.

    The real question is, why do you want users to not be able to highlight and presumably copy and paste certain elements? I have not come across a single time that I wanted to not let users highlight a certain portion of my website. Several of my friends, after spending many hours reading and writing code will use the highlight feature as a way to remember where on the page they were, or providing a marker so that their eyes know where to look next.

    The only place I could see this being useful is if you have buttons for forms that should not be copy and pasted if a user copy and pasted the website.

    评论

报告相同问题?