Reputation:
I'm trying to disable highlight on an image, when I drag my mouse over an image, it is highlighted.
Take a look:
Thanks a lot!
Upvotes: 31
Views: 40685
Reputation: 19652
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.
Upvotes: 1
Reputation: 11175
img {
-khtml-user-select: none;
-o-user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
user-select: none;
}
Upvotes: 11
Reputation: 2947
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;
}
Upvotes: 1
Reputation: 7996
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;
}
Upvotes: 0
Reputation: 47
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 */
}
Upvotes: 4
Reputation: 5769
Use user-select property:
img{
-khtml-user-select: none;
-o-user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
user-select: none;
}
Upvotes: 58
Reputation: 117771
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.
Upvotes: 14
Reputation: 36476
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"));
Upvotes: 6