有没有办法使DIV不可选? [英] Is there a way to make a DIV unselectable?

查看:229
本文介绍了有没有办法使DIV不可选?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有一个有趣的CSS问题给你!

Here is an interesting CSS questions for you!

我有一个textarea透明背景覆盖一些TEXT,我想用作一种水印。文本很大,占据了大部分textarea。它看起来不错,问题是当用户单击textarea它有时选择水印文本。我想要水印文字永远不可选择。我期待如果某些东西在z-index中较低,它是不可选择的,但浏览器似乎并不关心选择项目时的z-index图层。

I have a textarea with a transparent background overlaying some TEXT that I'd like to use as a sort of watermark. The text is large and takes up a majority of the textarea. It looks nice, the problem is when the user clicks in the textarea it sometimes selects the watermark text instead. I want the watermark text to never be selectable. I was expecting if something was lower in the z-index it would not be selectable but browsers don't seem to care about z-index layers when selecting items. Is there a trick or way to make it so this DIV is never selectable?

推荐答案

我写了一个简单的jQuery扩展来禁用选择一些时间回来:停用在 jQuery 中选择。您可以通过 $('。button')。disableSelection();

I wrote a simple jQuery extension to disable selection some time back: Disabling Selection in jQuery. You can invoke it through $('.button').disableSelection();

跨浏览器):

.button {
        user-select: none;
        -moz-user-select: none;
        -khtml-user-select: none;
        -webkit-user-select: none;
        -o-user-select: none;
} 

这篇关于有没有办法使DIV不可选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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