Pointer event combine hover css - html

I have a image that needs preventing people from saving or drag so I use
pointer-events: none;
but then I also want to add hover effect zoom like:
transform: scale(1.5);
Is there a way to achieve this?

You could set pointer-events:none; on the img, but wrap it in another element to trigger the hover action.
.image-wrapper {
display: inline-block;
overflow: hidden;
font-size: 0;
}
.image-wrapper:hover img {
transform: scale(1.5);
}
img {
transition: all .3s ease-out;
pointer-events: none;
}
<div class="image-wrapper"><img src="https://picsum.photos/200/300"></div>

As you've seen, pointer-events: none will stop the element reacting to any mouse movements or clicks at all, which isn't what you want.
To prevent dragging, you can just add the draggable="false" attribute to your image.
To cancel clicks, you can add an event listener to click and then call event.preventDefault() or return false. The quick and dirty way to do this is:
<img draggable="false" onclick="return false;"/>
There are much neater and nicer ways of attaching javascript to your elements, though.
It's important to know that disabling clicking and dragging will not prevent someone who really wants to save your image from saving it - and there's not really anything you can do if someone is really determined. If the user can see the image, the user can save the image. It might make it slightly more annoying, which might be enough for your case.

Related

End CSS Transition immediately during mouse-out

I want to show a image preview of a link using CSS. The behavior is something like this, when an user hovers over the link, the image preview appears after 1sec, but on hovering out, the preview is removed immediately. Now to ensure the preview appears after 1sec, I have used the transition property as
transition-property: visibility; transition-delay: 1s. While this is ensuring the preview gets visible after 1sec, it's transition from visible to hidden is also delayed for 1sec for obvious reason. Can I make sure that only the transition from hidden to visible does take 1sec, and not the vice versa using CSS?
You sadly showed no code.
But I assume you had the transition property on a class or id... and the :hover just changing a property, which is good in order to apply the transition on mouse in and out.
Weird thing is you mention the visibility property, which cannot be transitionned because it is not a "number" property. Maybe you meant opacity...
If you have the transition property in the :hover rule... It apply on hover (read on mouse enter) but squarely do not apply no "not hover" (read mouse out).
#target{
opacity: 0;
height: 400px;
width: 400px;
background: blue;
}
#target:hover{
opacity: 1;
transition: 1s;
}
<div id="target"></div>

Why firefox ignores css :hover selector?

I am setting up a simple animation to my button icon. The image in the button is supposed to go from 0.25 opacity default to 1 after hovering over it. Works well with chrome/edge, but firefox seems to ignore it (:hover).
The first guess was that firefox somehow does not support opacity. It does, as the default value of image set to 0.25 opacity is respected. There is no need for any prefixes what so ever. Also, the cursor does not change at all. Then thought maybe it is :hover, but that should have been 100% supported since the stone age.
Then it struck me that this could have been due to CSS grid level 2 layout design I am using, which actually is not yet fully implemented in browsers. I had enabled some layout flags in firefox but that has not brought the solution either. Anyhow making this sample shows it has nothing to do with the CSS grid layout.
I tried using javascript but did not help. I guess it is a bad practice anyway.
My last resort attempt was to try and increase specificity - no luck here either, go figure.
button {
padding: 20px 40px;
}
.images {
opacity: 0.25;
}
.images:hover {
opacity: 1;
cursor: pointer;
}
<button type="button"><img class="images" src="https://img.icons8.com/metro/160/settings.png"></button>
<button type="button"><img class="images" src="https://img.icons8.com/metro/160/settings.png"></button>
I expect the hover over increases the opacity of an image, as well as changes the cursor to pointer. I would be grateful for any feedback.
try this :
button {
padding: 20px 40px;
}
button .images {
opacity: 0.25;
}
button:hover .images{
opacity: 1;
}
button{
cursor: pointer;
}
<button type="button"><img class="images" src="https://img.icons8.com/metro/160/settings.png"></button>
<button type="button"><img class="images" src="https://img.icons8.com/metro/160/settings.png"></button>
I changed the way you call HTML elements in your CSS. For me it works on firefox 64.0.2 (64 bits).
EDIT:
Firefox does not ignore the :hover event. But the button element steal the priority of all mouse events. That's why inside element, as your <img> can't be hovered. This is simply the way Firefox interprets this code.
You can also have a look on this post.

CSS :hover works only on the lower half of the button

The page in question:
http://rainbowdoge.000webhostapp.com
The situation:
I have two buttons in the nav menu on the left side.
The upper one contains a hitbox (black for testing purposes), and an image of a rainbow. The image is changing the opacity on hover.
CSS code for that:
.icon {
opacity: 0.6;
backface-visibility: hidden;
transition: opacity 0.3s ease-in-out;
}
.iconHitbox:hover .icon {
opacity: 1;
cursor: pointer;
}
There is also an iframe on the page. The iconHitbox changes the iframe's source on click.
The problem:
If I hover over the top half of the button, the opacity doesn't change, as if a hover isn't even detected.
The solution I could think of:
I thought that maybe something else is getting in the way, but no, the setSrc() function works when I click on the upper half of the button.
This is happening because your #test1, #test2, and #test3 elements are being positioned half way over the rainbow circle. You'll need to move them out of the way.
The div with the id "test3" is overlapping with your icon. You can see it in the dev tools of your browser.
You have absolute set. If you remove absolute then adjust positioning you'll be good.
try:
#mainPageIcon {
background-color: black;
position: relative;
top: 25px;
}
.iconHitbox {
height: 8vh;
width: 8vh;
}

I can't click on follow/edit theme/like/reblog buttons on tumblr

For few weeks I've been trying to repair unclickable tumblr buttons (for example like, reblog, edit theme), but I can't. When I changed theme, everything worked perfectly. Thing is, I don't want to change theme, I want to know where the problem is.
I tried to hid my buttons with body > iframe:first-child { display: none !important; }
And it did disappear. Then I deleted this code and it showed me buttons, but I still couldn't click at any of them.
Then I tried
.tmblr-iframe.tmblr-iframe--desktop-loggedin-controls.iframe-controls--desktop {
z-index:999999999 !important;
}
iframeiframe.tmblr-iframe--desktop-loggedin-controls.iframe-controls--desktop {
-webkit-filter:invert(100%);
-moz-filter:invert(100%);
-filter:invert(100%);
right:3px;
-webkit-transition: all 0.4s linear;
-moz-transition: all 0.4s linear;
transition: all 0.4s linear;
z-index:999999;
}
But still, nothing changed. I also tried to clear my browser's cache and cookies. Still the same.
I don't know what to do anymore.
Edit. While trying to solve the problem by going into my page's html I found this after < / html >, in red
iframe scrolling="no" width="1"
height="1" frameborder="0" style="background-color:transparent;
overflow:hidden;
position:absolute; top:0; left:0; z-index:9999;" id="ga_target">
</iframe><script type="text/javascript">
And when I put this under < body >, buttons work, but my page disappears completly.
I checked if this code is on my main blog. It is, my not in red and before < / html >
Blog: smartchesters.tumblr.com
It is a little bit confusing what you are asking. Do you want to show the tumblr control buttons and have them clickable, or do you want to hide them entirely?
The reason you cannot click on the tumblr control buttons at the top right hand side is because of the properties of this element:
#bord {
position: fixed;
opacity: 1;
z-index: 9999999999;
width: 100%;
top: 0px;
height: 80px;
margin-left: -5px;
background-image: url("");
background-repeat: repeat;
}
If you toggle position:fixed on this element in the browser you will see that the tumblr control buttons become clickable. Or you can toggle the z-index attribute. Z-indexes in my opinion cause issues, there should be a way to lay out the document without needing to resort to z-indexes, except in an emergency.
I recently had one blog where I wanted to completely hide the tumblr controls (I was under the impression they were being added via javascript) however it seems that a pure css solution works:
iframe[class*="control"] {
display:none!important;
}
This looks for any iframe element whose class name contains "control"
Also the first part of this selctor looks off to me, is it definitely correct:
iframeiframe.tmblr-iframe--desktop-loggedin-controls.iframe-controls--desktop
Also, if you have code after your closing </html> you definitely need to fix or remove that. It looks like the google analytics code.
UPDATE
You have no closing </body> tag in your document. As well as the code falling outside the closing </html> tag. I would definitely run your html through a validator. It won't recognise the tumblr expressions like {PermalinkPage}
etc but it should help you pinpoint the tags that need closing properly.
https://validator.w3.org/

Make a whole div clickable with working :active css rule in IE10

I'm designing a clickable panel for an html app which contains multiple text elements and images.
From what I understand this is generally done with a div. Something like this:
<div class="myButton">
<h2>Text</h2>
<h3>Some more text</h3>
<img ...>
</div>
With a bit of styling and hooking up the click event this works fine but I am having problem with styling the active state:
.myButton {
cursor:pointer;
}
.myButton:active{
-ms-transition-duration: 0.2s;
-ms-transform: scale(0.95);
}
In this example I'm trying to do a css animation (IE only) but this could really be anything.
The problem is that the active state only works when I click on the div but doesn't work when I click on any of the children of the div.
Here is a JS Fiddle to show the scenario:
http://jsfiddle.net/S9JrH/13/
UPDATE: Thanks to David Thomas for pointing out a typo in the code and confirming that this works in Chrome.
Unfortunately, in IE10 this only works when you click on the lower part of the div, away from the text.
Does anyone know how to get this working properly in IE10?
Currently not possible (I think)
From what I can gather, this is currently not possible as the :active state of a child is not propagated up to the parent div. Both Internet Explorer 10 and Opera 11.64 failed to propagate the :active state up to the parent when testing with div elements.
Fiddle: http://jsfiddle.net/jonathansampson/UrN39/
Workaround
The only other solution that comes to mind would be to use event propagation in JavaScript. Fortunately the events of a mousedown will propagate up on the DOM, and onto the parent div. The following example utilizes jQuery:
$(".myButton").on("mousedown mouseup mouseleave", function(e){
$(this).toggleClass( "active", e.type === "mousedown" );
});
Note here that I have modified the :active pseudo-class to be an actual class .active. This has been tested in IE10 and works. Given the approach, it should work without any problem in just about every major browser.
Fiddle: http://jsfiddle.net/jonathansampson/S9JrH/8/
Why don't you use HTML <button> element. It's created for your case. Div doesn't take focus, while button gets.
You can use the CSS pointer-events: none; on a child element that you would like to disregard mouse events and it will bubble up appropriately to its parent.
I overlay the the element using :after so that children are not clickable.
.myButton:after {
content: '';
display: block;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: #fff;
opacity: 0;
filter: alpha(opacity=0);
}
.myButton:active, .myButton *:active{
-ms-transition-duration: 0.2s;
-ms-transform: scale(0.95);
}
I will be honest I have no idea if you can use *:pseudo-selector in IE but chrome you can so it's worth a shot.