How to prevent users from selecting the button text, while playing a game for example? Read the whole description PLEASE 🙏. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 41

How to prevent users from selecting the button text, while playing a game for example? Read the whole description PLEASE 🙏.

Let's say I have a dynamic shooting game. So there are controls like a D-pad and some action buttons like a fire button, which looks like this in my code <button>Fire</button>. The problem is, when a player taps that button rapidly or long taps the button, the text gets highlighted. Things are even worse on phones, because of the text menu popping up. YES, I know I could replace button tags with <input type="button" value="Fire" />, but I'd like to stick to button tags if possible.

19th Jun 2020, 11:30 AM
🇺🇦 Vitya 🇺🇦
🇺🇦 Vitya 🇺🇦 - avatar
3 Answers
+ 11
Add: button{ user-select:none; }
12th Jul 2020, 7:48 PM
Goke Ekundayo
Goke Ekundayo - avatar
+ 8
If I understood correctly, you're asking to disallow selecting text. user-select: none; With vendor prefixes should work. For more info and browser support: https://stackoverflow.com/questions/826782/how-to-disable-text-selection-highlighting https://caniuse.com/#feat=user-select-none https://css-tricks.com/almanac/properties/u/user-select/
19th Jun 2020, 12:04 PM
Roneel
Roneel - avatar
+ 6
Just add something to roneel's answer user-select only work for chrome and Opera browser, here is the full: user-select: none; /* supported by Chrome and Opera */ -webkit-user-select: none; /* Safari */ -khtml-user-select: none; /* Konqueror HTML */ -moz-user-select: none; /* Firefox */ -ms-user-select: none; /* Internet Explorer/Edge */
20th Jun 2020, 11:05 PM
Jingga Sona
Jingga Sona - avatar