How to prevent content selection with CSS?

17

How to prevent text / content selection from my web page with CSS?

This would be extremely useful for buttons, anchors, tags and other elements that could be selected without the user's interest ...

    
asked by anonymous 18.12.2013 / 17:42

2 answers

19

Using the following CSS rules for elements that can not be selected:

#seletor {
   -webkit-touch-callout: none;
   -webkit-user-select: none;
   -khtml-user-select: none;
   -moz-user-select: none;
   -ms-user-select: none;
   user-select: none;
}
    
18.12.2013 / 17:42
-2
<head>
    <script type="text/javascript">
        function RemoveSelection() 
           {if (window.getSelection) {window.getSelection().removeAllRanges();}}
    </script>
</head>
<body onmouseup="RemoveSelection();">
    Select some content on this page with the mouse!
</body>
    
13.04.2014 / 21:17