css 讓文字不被選中之-moz-user-select 屬性介紹

他在ie下也能選中文字,但是選中其他列表,不會(huì)選中文字,原來(lái)它是在不同div中,屬于不同的范圍,而同事是放在同一個(gè)table中,當(dāng)然會(huì)選中。
而在firefox下,文字不會(huì)被選中,查看google calender的css,原來(lái)還有-moz-user-select這個(gè)屬性,很好玩!
最后采用一個(gè)了js方法,即onselectstart=function{return false;},不讓頁(yè)面進(jìn)行選擇,呵呵,這是很多網(wǎng)站不讓復(fù)制采用的方法。
防止選取 <div> 元素的文本:
div { -webkit-user-select: none; /* Safari */ -ms-user-select: none; /* IE 10+ and Edge */ user-select: none; /* Standard syntax */ }
Summary
-moz-user-select is a Mozilla property extension to CSS that is used to determine whether or not an element may have its content selected.
Media: interactive
Possible uses include: prohibiting the selection of content in attempts to reduce blatant copying.
Syntax
TARGET_ELEMENT{-moz-user-select: none;}Legal Values
Value | Description |
---|---|
inherit | Inherit the value from the parent element. |
none | None of the content may be selected. |
text | Only the text within the element may be selected. |
element | A single element may be selected (from many). |
elements | Multiple elements may be selected. |
all | The contents must either be selected in entirety or none at all. |
toggle | The contents are selected "following a standard toggling content model" [1]. |
tri-state | unknown |
-moz-all | unknown |
Usage Examples
This sample code provides a simple "Hello, World!" text which prevents the user from selecting the content:
<span style="-moz-user-select: none;"> Hello, World! </span>
Notes
This property is similar to the user-select property of CSS3.
When the 'none' value was applied to a heading element the content could still be selected.
According to the W3C, the "User agent's default style sheet may override this value. For example, user agents typically do not allow selection of the contents of a BUTTON element. [2] As the -moz-user-select was designed to mimic the user-select property, the same applies.
Specification Conformance
Doesn't conform to CSS standards; A Mozilla CSS Extension.
Browser Compatibility
Netscape 6+
Mozilla 0.6+
Firefox 1.0+
See Also
-moz-user-focus
-moz-user-input
-moz-user-modify
css中的 “-moz-user-select”和“-khtml-user-select”屬性是什麼意思?以及它們的用法?
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> h1{ -moz-user-select:-moz-none; } </style> </head> <body> <h1>這里在firefox中會(huì)顯示不同</h1> <pre> 屏蔽選擇的樣式定義:-moz-user-select屬性(只支持ff)。 屬性有三個(gè)屬性值: 1、 none:用none,子元素所有的文字都不能選擇,包括input輸入框中的文字也不能選擇。 2、 -moz-all:子元素所有的文字都可以被選擇,但是input輸入框中的文字不可以被選擇。 3、 -moz-none:子元素所有的文字都不能選擇,但是input輸入框中的文字除外。 IE瀏覽器下是通過(guò) onselectstart=”javascript:return false;”事件來(lái)實(shí)現(xiàn)該功能。 </pre> </body> </html>
-khtml-是蘋(píng)果的那個(gè)瀏覽器的 好像現(xiàn)在使用-webkit-user-select: none
相關(guān)文章
jquery實(shí)現(xiàn)select下拉框美化特效源碼
jquery實(shí)現(xiàn)select下拉框美化特效,實(shí)現(xiàn)效果簡(jiǎn)潔大方,是一款非常實(shí)用的特效源碼。2015-08-27CSS美化下拉框select在火狐和谷歌瀏覽器下已測(cè)試
本示例要模仿的是下拉框,經(jīng)過(guò)美化的偽下拉,右邊的小三角是用css3實(shí)現(xiàn)的,鼠標(biāo)經(jīng)過(guò)的時(shí)候有旋轉(zhuǎn)特效2014-05-13- 這篇文章主要介紹了使用CSS3的::selection改變選中文本顏色的方法,也就是說(shuō)可以將默認(rèn)的藍(lán)色底色改為其他顏色,really cool,需要的朋友可以參考下2015-09-29
- 這篇文章主要介紹了用CSS和Div美化SELECT樣式的簡(jiǎn)單方法,同時(shí)提到了select相關(guān)的兼容性寫(xiě)法,需要的朋友可以參考下2015-08-06
純css為select添加樣式(無(wú)腳本)實(shí)現(xiàn)
改變select默認(rèn)的樣式,一般情路情況下通過(guò)ul,li來(lái)模擬來(lái)實(shí)現(xiàn);Jquery插件也是這樣,接下來(lái)介紹一種不寫(xiě)腳本,只用單純的css來(lái)實(shí)現(xiàn)。在IE系列下,選中某個(gè)選項(xiàng)的時(shí)候會(huì)有背景2013-02-21- 去年我學(xué)jQuery的時(shí)候,曾經(jīng)做過(guò)一點(diǎn)選擇器(selector)的筆記,今天是CSS的選擇器,以后還有一部分xPath的選擇器。今天的筆記中包括44個(gè)選擇器,基本涵蓋了CSS 2和CSS 3的2012-12-18
用CSS讓img input select button 圖片,文本框,下拉菜單,按扭垂直居中的
一直以來(lái),在HTML中,img input select button 這里元素,垂直對(duì)齊,比較難。結(jié)果我長(zhǎng)大了。我發(fā)現(xiàn)了一個(gè)現(xiàn)像,其實(shí)解決這些問(wèn)題只是一句話(huà)的事。2011-03-08css教程:css指令,兼容,注釋,selector-CSS教程-網(wǎng)頁(yè)制作-網(wǎng)頁(yè)教學(xué)網(wǎng)
1.2 跟css有關(guān)的標(biāo)記,指令 1.2.1 link <link rel="stylesheet" type="text/css" href="sheet1.css" media="all" />2008-10-17CSS Hack整理-CSS教程-網(wǎng)頁(yè)制作-網(wǎng)頁(yè)教學(xué)網(wǎng)
CSS Hack是在標(biāo)準(zhǔn)CSS沒(méi)辦法兼容各瀏覽器顯示效果時(shí)才會(huì)用上的補(bǔ)救方法,在各瀏覽器廠(chǎng)商解析CSS沒(méi)有達(dá)成一致前,我們只能用這樣的方法來(lái)完成這樣的任務(wù). 我進(jìn)行前端開(kāi)發(fā)的2008-10-17- 本文給大家介紹css代碼去掉select的下拉箭頭樣式的方法,代碼簡(jiǎn)單易懂,需要的朋友可以參考下2016-09-02