开发者

HTML How can I prevent someone highlighting text within divs?

开发者 https://www.devze.com 2023-03-28 12:02 出处:网络
Firstly yes I have found this link: Is there a way to make text unselectable on an HTML page? but it doesn\'t seem to work for me. I have lots of divs containing text, making a customised table. Whe

Firstly yes I have found this link:

Is there a way to make text unselectable on an HTML page?

but it doesn't seem to work for me. I have lots of divs containing text, making a customised table. When a user uses ctrl and clicks on multiple rows sometimes the table content gets highlighted too. Then this causes a problem when I wish to scroll across the开发者_StackOverflow中文版 overflow of the table.


You can use this CSS:

.unselectable {
   user-select: none;
}


Use CSS to solve this problem:

body {
    -webkit-user-select: none; /* Webkit */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* IE 10 */
    /* Currently not supported in Opera but will be soon */
    -o-user-select: none;
    user-select: none;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号