I'm trying to disable highlight on image, when i move with my mouse on image and drag,
Take a look :
Thanks alot!
I'm trying to disable highlight on image, when i move with my mouse on image and drag,
Take a look :
Thanks alot!
Use user-select property:
img{
-khtml-user-select: none;
-o-user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
user-select: none;
}
You can try this (this won't work in all browsers):
img::-moz-selection {
background-color: transparent;
color: #000;
}
img::selection {
background-color: transparent;
color: #000;
}
Or you can use a <div>
with the appropriate width and height set and use a CSS background image on it. For example I use this on my site:
<div id="header"></div>
#header {
height: 79px;
width: 401px;
background: url(http://nclabs.org/images/header.png) no-repeat;
}
And finally you can use Javascript to programatically disable it.
img {
-khtml-user-select: none;
-o-user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
user-select: none;
}
This disabled highlighting on a DOM element:
function disableSelection(target){
if (typeof target.onselectstart!="undefined") // if IE
target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") // if Firefox
target.style.MozUserSelect="none";
else // others
target.onmousedown=function(){return false;}
target.style.cursor = "default";
}
Use it like this:
disableSelection(document.getElementById("my_image"));
img{
-ms-user-select: none; /* IE 10+ */
-moz-user-select: none; /* Firefox all */
-webkit-user-select: none; /* Chrome all / Safari all */
user-select: none; /* Likely future */
}
To remove the selection of text and images from entire website use body selector
body {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
If you are facing a problem when you click on the image, here is the solution to that.
img {
-webkit-tap-highlight-color: transparent;
}
if not working then please try that in your parent of the image that contains the whole width of the image.
In case some people here are interested about the sass mixin:
// Prevent users to select an element
@mixin no-select {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}