I have this https://paste.ofcode.org/pazWmmkQURzyhtc2rNnfjx the hover works fine on my computer but I realized you cannot hover on mobile. when I change it to :active instead it makes me hold it to keep the back part of the card displayed. Is there a way to make it so I just have to click it for it to rotate and click again for it to rotate back to the front?
css card flip on click instead of hover |
(Oct 12, 2020 03:31 PM)Mank Wrote: I have this https://paste.ofcode.org/pazWmmkQURzyhtc2rNnfjx the hover works fine on my computer but I realized you cannot hover on mobile. when I change it to :active instead it makes me hold it to keep the back part of the card displayed. Is there a way to make it so I just have to click it for it to rotate and click again for it to rotate back to the front? You may consider using JavaScript to apply the hover transformation on click with mobile devices. For example: When a user clicks the card, it'll check to see if the mobile-click class exists. If it doesn't, it adds it. Otherwise it removes it. Thus creating a toggle effect on that class. You could then apply that with CSS via the likes of: Code .card:hover > .front, .card.mobile-click > .front {}Which effectively just makes the rule applicable only when the mobile-click class exists on a card. <Disease />
(Oct 12, 2020 06:06 PM)Disease Wrote: You may consider using JavaScript to apply the hover transformation on click with mobile devices. For example: Thanks, I appreciate it but it did not work (Oct 12, 2020 06:40 PM)Mank Wrote: Thanks, I appreciate it but it did not work DId you put stuff in Code .card:hover > .front, .card.mobile-click > .front {}
Oct 13, 2020 06:49 AM
(This post was last modified: Oct 13, 2020 06:50 AM by Mister Slyther.)
On mobile, you can just use :focus, and :hover on phone acts as a click btw.
I would not resort to using Javascript un-necessarily, you don't need to complicate things. (Oct 13, 2020 06:49 AM)Mister Slyther Wrote: On mobile, you can just use :focus, and :hover on phone acts as a click btw. Could I pm you please (Oct 13, 2020 06:49 AM)Mister Slyther Wrote: On mobile, you can just use :focus, and :hover on phone acts as a click btw. Using the :focus pseudo-class isn't the way to go, as it isn't supported by Safari. It'll work fine in other browsers on mobile, though. But you'll alienate a significant percentage of your mobile users going that route. Same as the :active psuedo-class, which in non-Safari browsers would active on tapping an element. In theory you should be fine with the original code, using just :hover pseudo-classes. But the problem is it's unreliable. Often times devices will consider the first tap on an element to be a hover event, and subsequent taps to be clicking. You need to effectively click off the element to reset the event. Hence the JS solution- it eliminates this quirk, and is more reliable and consistent across devices. <Disease />
Oct 13, 2020 02:25 PM
(This post was last modified: Oct 13, 2020 02:26 PM by Mister Slyther.)
(Oct 13, 2020 02:19 PM)Disease Wrote: Using the :focus pseudo-class isn't the way to go, as it isn't supported by Safari. It'll work fine in other browsers on mobile, though. But you'll alienate a significant percentage of your mobile users going that route. Same as the :active psuedo-class, which in non-Safari browsers would active on tapping an element. 2 years ago when I took an SCSS course, the instructor actually did a fully functional card flip using CSS only. I'll be happy to link the source tomorrow. However, I can't remember if he took what you said into consideration. Will check. |
|
|


