I need to disable the highlighting of selected text on my web app. I have a good reason for doing this and know that this is generally a bad idea. But I need to do it anyway. It doesn't matter if I need to use CSS or JS to do it. What I'm mainly going for is the removal of the blue color given to highlighted elements.
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
I believe what you mean is selecting text (e.g. dragging the mouse across to highlight). If so, this will cancel the selection action in IE and Mozilla:
I think you're looking for the :focus pseudo class. Try this:
It will give your input a pretty purple/pink color when selected.
I'm not sure which properties you have to (un)set, but I think you can find out yourself using trial and error.
Also note that the highlighting or absence thereof is browser specific!
The CSS3 solution:
There is also a webkit prefix for the user-select, but it makes some form fields impossible to focus (could be a temporary bug), so you could go with the following pseudo-class for webkit instead:
If your ultimate goal is to make copy and paste of text more difficult, Javascript and CSS are not the right technology because you cannot disable the browser's view-source function.
Some other ideas (none of them ideal):
Do you mean highlighting of text when you drag your mouse over it?
Best way to do this would be using a CSS3 property called ::selection, however being CSS3 it isn't well-supported yet. Go ahead and look that up, otherwise maybe there's a way to do it with Javascript.
U can use the css pseudo class selector (::selection and ::-moz-selection for firefox). Example