I am making a custom Application in Android. I am displaying a html page with an img tag inside a div.
<div class="press">
<img src="but.png" width="150" height="62" border="0"/>
</div>
In the javascript I am writing:
$(".press").bind("click",function()
{
//display something
});
When I click on the image, the click is working but the image is surrounded with a blue overlay.
Image 1
Image 2 when image clicked
I dont understand how to remove it. I have tried many ways but none of the answers work. Please help. Thanks
You can prevent selection on your page through css. You can change the * selector to the element selector you want to prevent from selection.
/*IE9*/
*::selection
{
background-color:transparent;
}
*::-moz-selection
{
background-color:transparent;
}
*
{
-webkit-user-select: none;
-moz-user-select: -moz-none;
/*IE10*/
-ms-user-select: none;
user-select: none;
/*You just need this if you are only concerned with android and not desktop browsers.*/
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
input[type="text"], textarea, [contenteditable]
{
-webkit-user-select: text;
-moz-user-select: text;
-ms-user-select: text;
user-select: text;
}
Try this:
CSS
.press, img, .press:focus, img:focus{
outline: 0 !important;
border:0 none !important;
}
You could use CSS:
** HTML **
<button class="press">
<img src="but.png" width="150" height="62" border="0"/>
</button>
** CSS **
.press{
outline-width: 0;
}
.press:focus{
outline: none;
}
Answer take from here: How to remove the border highlight on an input text element
It may be the background color or the border color on the div that includes the button. Else
use a code like following to remove the css after click completely
$("#myButton").click(function(){
$("#displayPanel div").removeClass('someClass');
});
Related
I'm working on a site that uses this bootstrap theme. When the mouse hovers over any image a zoom icon appears - how do I remove it?
I have tried removing class="zoomIcon" and looked on this site as well as searching on Google.
HTML:
<div class="product-main-image-container">
<img src="../../images/products/prod1.png" alt="" class="product-loader" style="display: none;">
<span class="thumbnail product-main-image" style="position: relative; overflow: hidden;">
<img src="../../images/products/prod1.png" alt="">
<img src="../../images/products/prod1.png" class="zoomImg"
style="position: absolute; top: -0.0456852791878173px; left: -1.23350253807107px; opacity: 0; width: 400px; height: 400px; border: none; max-width: none; max-height: none;">
</span>
</div>
You can add this to your CSS:
<style>
img:hover {
cursor: default;
}
</style>
I hope this helped you!
You can override this cursor behavior by either modifying the CSS that is making it happen (it looks like a CSS file called style.css) or by writing your own rule to make it stop.
The rule is on .product-main-image in line 432 of the style.css file, and to overwrite it, you would need a rule like this:
.product-main-image{cursor:default;} or any other cursor style you wish
class product-main-image has the zoom icon:
.product-main-image{
cursor: zoom-in; cursor: -webkit-zoom-in; cursor: -moz-zoom-in
}
http://screencast.com/t/NcdCxnrrW4
Just remove this class from the span or change the cursor on this class to something else http://www.w3schools.com/cssref/pr_class_cursor.asp
This is not from a class.
img:hover{
cursor:pointer;
}
Source : https://developer.mozilla.org/en-US/docs/Web/CSS/cursor1
Unrelated : You shouldn't leave the 'alt' tags empty, they are important to accessibility and SEO.
You can use the CSS cursor property.
Then you can just assign it to default on hover
img:hover {
cursor: default;
}
I want to remove the selection-highlight on all images on my page.
I found some useful additions like :
CSS
img {
-webkit-user-select:none;
-khtml-user-select:none;
-moz-user-select:none;
-o-user-select:none;
user-select:none;
pointer-events:none
}
But when I press down my mouse button and select multiple things or press Ctrl+A for "select all" my images get highlighted with a blue shade.
I tried to change it via :
CSS
img::selection {background:transparent;color:inherit;}
img::-moz-selection {background:transparent;color:inherit;}
But that don't have any effect.
Does someone have a useful solution or is there none yet ?
P.S. : I don't care about selecting my images - I just want to get rid of that blue shape.
Here goes a wacky solution I came up with...
1) After some testing I found that this only occurs on mozilla. Other browsers don't show the blue selection on images when the code
img::selection {
background: transparent;
}
is set.
2) Even mozilla - only has a problem with image elements. But other elements with a background-image obey the ::selection rule.
So technically we could work around this assuming we add an empty span in our markup after each img element which we set to display:none;
Then we can add some CSS which will only run in firefox which sets the images to display:none and places a background-image on the adjacent span.
Like this:
FIDDLE
**
img::selection {
background: transparent;
}
img + span {
display: none;
}
#-moz-document url-prefix() {
img {
display: none;
}
img + span {
background: url(http://placehold.it/200x200) no-repeat;
width: 200px;
height: 200px;
display: block;
}
}
<div>Hello there </div>
<img src="http://placehold.it/200x200" /><span></span>
<div>Hello there </div>
1: http://jsfiddle.net/GMuzV/30/
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"));
I have a span inside another span. I would like to allow the user to be able to select the text from the parent span, but not the child one.
Note: user-select (family) does not work. It prevent the selection to start or end in this area, but the text is still in the end clipboard result if I surround it with the select in the text from the parent span.
For example:
<head>
<style>
.hole-hint {
display: inline-block;
position: absolute;
bottom: 45%;
font-size: 12px;
color:rgb(255, 0, 0);
background-color:rgba(255, 225, 225, 0.5);
z-index:1;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
.hole {
padding-top: 7px;
position: relative;
background-color:#EEEEEE;
}
</style>
</head>
<body>
<span> this is the parent text<span class="hole"><span class="hole-hint">no copy</span></span>and this is text on the other side </span>
</body>
</html>
I had a similar need, I used place holders for text that wasn't entered yet. However if the user wanted to copy that block of text they would never want the place holders in the copied text. I came up with the following solution.
Here is an example, it uses some jquery but that could be replaced
CSS (not really needed just for fun)
div.copying { background-color: yellow; }
div.copying .nocopy { display: none; }
HTML (Note: if you wanted to apply to the entire page, move oncopy to )
<body>
<div>text not related to the copy, dont select this</div>
<div oncopy="handleHideCopy(this);" class="container">
<span>the text between ><span class="nocopy"> I don't want this text copied </span><span>< will be excluded from copy, or at least in IE</span>
</div>
<div>and don't select this either</div>
</body>
JS
function handleHideCopy(el)
{
$(el).addClass('copying');
var innerHtml = el.innerHTML;
$(el).find('.nocopy').remove();
setTimeout(function(){
$(el).removeClass('copying');
$(el).children().remove();
el.innerHTML = innerHtml;
},300);
}
The reason why this works is because oncopy is called on the parent element before the copy takes place, and the content that must be hidden has to actually be removed, as display:none does absolutely nothing for copy.
Instead of using innerHTML for large amounts of html a more targeted DOM remove/insert should be used to remove the content and put it back where it belongs. I don't have an example handy for that.
I am working on a Phone Gap Project.I am using HTML,JAVA SCRIPT and CSS.
I have implemented onclick ,mapping and ahref functionality in my project.While using this functionality either for onclick or mapping or ahref --while selecting the image or text it gets highlighted.
I don't want it get highlighted.I tried implementing this following code
noSelect
{
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-o-user-select: none;
user-select: none;
}
But,this code made no difference in the SELECTING VIEW.
So,please suggest me a way to handle this and solve my problem.
EDIT:
This is how i have used it in mapping and image but it isn't working.
mapping
<div id="main" class="main" ><img src="img/abc.png" alt="abc" usemap="#abc" class="noSelectInputBox:focus"/></div>
image source
document.getElementById("detail").innerHTML = '<img src="img/image1.png" onclick="detail()" class="noSelectInputBox:focus"/> '
try adding the following css to yours:
noSelectInputBox:focus
{
-webkit-tap-highlight-color:rgba(0,0,0,0);
outline:none;
-webkit-focus-ring-color:rgba(0 0 0 0);
}
Hope that helps.
Writing the following code in your css file. While using this we can disable highlighting the contents on touch.
*{
/* Prevent any object from being highlighted upon touch event*/
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
I am making a website in dreamweaver CS5. I exported the images from photoshop an inserted them into a table. When I view the site all the images are selectable(you are able to drag them to your desktop). How do I change this??? I want to do it with an onclick method in addition how would I achieve this?
<td><img src="images/people_03.png" name="one" width="1000" height="156" id="one" ONCLICK="closeimages();"/></td>
I stumbled upon this question while struggling with the same problem but the accepted answer was not a possible solution for me.
I used the info found here , in particular adding the following styles to my body, inside the css (this worked for me in Firefox, Chrome and Opera, I cannot test for IE)
-moz-user-select: none;
-webkit-user-select: none;
user-select: none;
The unselectable html tag seems also helpful, but it's apparently supported only by IE and Opera:
<img src="1.jpg" unselectable="on">
as well as the javascript solution, that is said to work on IE and webkit browsers:
<script>
window.onload = function() {
document.body.onselectstart = function() {
return false;
}
}
</script>
Note. As Albert Renshaw pointed in the comment this method no longer works in Chrome > 50.
I would use pointer-events: none; in my CSS
img {
pointer-events: none;
}
Reliable Pure CSS Solution
Applying the following 2 CSS properties to your <img> element(s) will achieve exactly what you described:
pointer-events: none;
user-select: none;
This works reliably across all modern browsers.
Example: (Try to select and drag the image with your cursor! :D)
img {
pointer-events: none;
user-select: none;
}
<img src="https://source.unsplash.com/random/200x200" alt="sample image" />
The only downside is that pointer-events: none causes your :hover, :active and other pointer-related CSS pseudo-classes to stop working.
In order to solve this, you should use a <div> or something as a wrapper for your <img> and then apply your :hover, :active pseudo-classes on that wrapper as opposed the <img> itself.
Example:
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
/* Don't mind the code above... */
.image-wrapper {
transition: ease .5s;
}
.image-wrapper:hover {
transform: scale(1.3)
}
.image {
pointer-events: none;
user-select: none;
}
<div class="image-wrapper">
<img class="image" src="https://source.unsplash.com/random/200x200" alt="sample image" />
</div>
If you also don't want to or can't change your HTML markup, then you're gonna have to resort to some JavaScript:
imgElement.addEventListener('selectstart', () => false);
Easiest way I think would be to make the images as css background images to each cell