如何設(shè)置CSS以禁止文本選擇
在CSS中,您可以使用user-select
屬性來禁止文本選擇。user-select
屬性定義了用戶是否可以選擇文本。
要將文本設(shè)置為不可選,您可以將user-select
屬性設(shè)置為none
。
.noselect { -webkit-user-select: none; /* Safari */ -moz-user-select: none; /* Firefox */ -ms-user-select: none; /* IE10+/Edge */ user-select: none; /* 標準語法 */ }
在上面的示例中,任何具有noselect
類的元素都將禁止文本選擇,這可以通過在HTML元素上添加class="noselect"
來實現(xiàn)。
<div class="noselect"> This text cannot be selected. </div>
user-select
屬性在IE9及更早版本的Internet Explorer中不受支持,如果您需要支持這些瀏覽器,請考慮使用其他方法或技術(shù)來實現(xiàn)文本禁止選擇的功能。
版權(quán)聲明:除非特別標注,否則均為本站原創(chuàng)文章,轉(zhuǎn)載時請以鏈接形式注明文章出處。