Disable Text Selection In WebPage Using CSS.
To Disable Text Selection it takes only Two steps:-
- Make a HTML file and define markup for webpage
- Make a CSS file and define styling to disable the text
Step 1.Make a HTML file and define markup for web page
We make a HTML file and save it with a name Index.html
<!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="disable.css"> </head> <body> <h1>Disable Text Selection In Website Using CSS</h1> <p class="select">Select The Text In This Paragraph This Is Selectable Like Any Other Text</p> <p class="no_select">Try To Select This Text You Are Not Able To Select This Text In Modern Browsers</p> </body> </html>
Step 2.Make a CSS file and define styling to disable the text
We make a CSS file and save it with name disable.css
body { background-color:#eae2ec; font-family:helvetica; text-align:center; margin:0px auto; padding:0px; } h1 { margin-top:100px; color:#424242; font-size:40px; } h1 p { margin:0px; font-size:18px; color:black; text-decoration:underline; } .select { font-size:30px; font-weight:bold; color:#4000FF; } .no_select { font-size:30px; font-weight:bold; color:#c000ff; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; }
In this step we use the user-select property to disable the text selection and also we use cross-browser prefix so that this should work in most of the browser and also with some old browsers.You may also like Block Inspect Element using JavaScript.
Comments
Post a Comment