Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop user-selection in Bootstrap navbar

I would like to prevent user-selection to be possible on a Boostrap navbar, such as :

http://getbootstrap.com/examples/navbar-fixed-top/

How to stop user-selection ?

I tried user-select: none; but it fails if you do CTRL-A.

Note : I don't want to stop user to copy text on the page, but I want to provide better user experience by avoiding selection of navbar elements.

like image 367
Basj Avatar asked Dec 02 '22 15:12

Basj


2 Answers

In bootstrap 4.5 and above, you can just use class="user-select-none"

like image 87
Sachin srinivasan Avatar answered Dec 11 '22 04:12

Sachin srinivasan


You could do it like this:

Bootply - DEMO

.navbar {
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  -o-user-select: none;
  user-select: none;    
}

More Info:

Mozilla MDN user-select

CSS-Tricks user-select

Solution 2: Disable user selection when press CTRL+A

You could also do it by set the ::selection background color to none

Bootply - DEMO

div.navbar *::-moz-selection {
    background: none !important;
}
div.navbar *::selection {
    background: none !important;
}
.navbar {
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  -o-user-select: none;
  user-select: none;    
}
like image 30
Anonymous Avatar answered Dec 11 '22 03:12

Anonymous