Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable highlight on a image

Tags:

html

css

People also ask

How do you remove highlight from a picture?

Removing Highlighter Obfuscation from ImagesFind an image that has blacked-out text, open it in the Photos app, and tap "Edit" in the top right to open the image editor. You'll be using the tools at the bottom to remove the highlighter.


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;
}

Try to put it as a css background instead of an img element.


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 */      
}