I want the word "gallery" to do a css3 3D rotate transition and reveal the words "art/art2" unfortunately I'm having a mud of a time getting it to work.

HTML

<div class="wrap">
<div class="gallery">Gallery</div>
<div class="back"><a href="" class="link_a">Art</a><a href=""
class="link_b">Art2</a>
</div>

CSS

.gallery {font-size:4em;color:orange;}
.gallery a:hover {color:orange;position:absolute;-webkit-transition: all .1s ease-in-out;-webkit-perspective:600px; none;-webkit-transform-style: preserve-3d;}
.back {font-size:4em;position:absolute;top:2px;}
.back a:hover {color:grey;-webkit-transform: rotateX(180deg);-webkit-perspective: 500px;}

Dani AI

Generated

Quick diagnosis and recommended pattern (CSS-only): the flicker that described is the expected result when the element that receives the hover is the same element being transformed — the transform moves the element away from the cursor so the hover ends and the animation snaps back. Also several small problems in the original snippet cause unexpected behavior (for example -webkit-perspective:600px; none; is malformed, and .gallery a:hover targets nothing if .gallery contains no anchor).

The reliable CSS pattern is: a wrapper that provides perspective, an inner “flipper” that has transform-style: preserve-3d and the transition, and two faces (front + back) positioned exactly on top of each other. The back face is rotated 180deg initially and both faces use backface-visibility: hidden. Flip the flipper on hover of the wrapper — that keeps the hover area stable and stops the flicker.

Example (concise):

<div class="flip-wrap">
  <div class="flip">
    <div class="front">Gallery</div>
    <div class="back"><a class="link_a">Art</a><a class="link_b">Art2</a></div>
  </div>
</div>
.flip-wrap { display:inline-block; -webkit-perspective:800px; perspective:800px; }
.flip { position:relative; -webkit-transform-style:preserve-3d; transform-style:preserve-3d;
       -webkit-transition:-webkit-transform .6s; transition:transform .6s; }
.front,.back { position:absolute; top:0; left:0; width:100%;
               -webkit-backface-visibility:hidden; backface-visibility:hidden; display:block; }
.back { -webkit-transform:rotateX(180deg); transform:rotateX(180deg); }
.flip-wrap:hover .flip { -webkit-transform:rotateX(180deg); transform:rotateX(180deg); }

Troubleshooting notes: give the flipper a stable width/height (or matching inline-block sizing) so the hover area doesn’t collapse; apply perspective to the wrapper (not to the hovered face); include both vendor-prefixed and unprefixed properties for best Chrome/Safari behavior; if back links aren’t clickable, confirm backface-visibility and transform-style are present and that no ancestor creates a new stacking context. This approach implements the flip purely in CSS and avoids the hover-flicker loop that has appeared in earlier attempts.

Recommended Answers

All 23 Replies

Before we even bother looking at this code in details... What browser are trying this with? The transform property which you didn't include is supported by IE10 and Firefox. If you are trying with IE your code will not work.

You only included the WebKit alternative which is supported by opera chrome and safari.

At this time I'm only testing with Webkit browsers, which is obviously Chrome / Opera, that is why I only have one vendor prefix.

ARghh I can't figure this out ! Of all style sheet rules this is playing hardball.

You forgot to add display:block; to the elements you need to rotate.

.gallery {font-size:4em;color:orange;display:block;}
    .gallery a:hover {color:orange;position:absolute;-webkit-transform: rotateX(125deg);-webkit-perspective: 300px;display:block;}

I added {display:block} to both elements, I know it probably is wrong, I wanted to test if it would work, unfortunately, no.

HTML

<div class="wrap">
  <div class="gallery">Gallery</div>
  <div class="back">
    <a href="" class="link_a">Art</a>
    <a href="" class="link_b">Art2</a>
  </div>
</div>

CSS

.gallery {
  font-size:4em;color:orange;
}
.gallery a:hover {
  color:orange;
  position:absolute;
  -webkit-transition: all .1s ease-in-out;
  -webkit-perspective:600px;
  -webkit-transform-style: preserve-3d;
}
.back {
  font-size:4em;
  position:absolute;
  top:2px;
}
.back a:hover {
  display:block;
  color:grey;
  -webkit-transform: rotateX(180deg);
  -webkit-perspective: 500px;
}

Here's a working JS BIN

Does JSBin support vendor prefixes, all I see is flickering when I hover ?

Yes, JSBIN supports vendor prefixes.

You see the flickering because when you hover the item, it rotates into another position and your mouse is no longer on top of it, which makes it revert to it's original position where your mouse is. That makes a loop, hence the flickering.

Rotating on hover doesn't seem like a good idea, unless you can figure out a way to keep the object in the same place while rotating. Play around with position on your console, it might just pop into place.

If you keep having problems just let us know so we can try to stop the flicker^^

I'm continuing to experience problems, arghh. I changed both the .gallery a:hover and the .back class to position:relative; as you mentioned, no progress has been made :(

Do you have some sort of end result in mind. Can you make a png of the before and after so we can try to replicate?

The end result is the word "gallery" rotates with a CSS3 3D rotation and reveals the word "art/art2" which are individual links.

Is this JS BIN close?

I am having some issues with the links, as they aren't clickable atm, but I'll try to get on that later.

The word "gallery" should rotate on the X, then -backface visibility:hidden for the word "gallery", then show the word "art/art2". I don't know if the code is working on your end with JSBin but all I'm seeing is flickering. I tried JsFiddle, same results <sigh> :-)

This last one shouldn't flicker... gotta take a look later.

But if you need an animation to rotate the word and then hide it, I would suggest jQuery, since you can use event callbacks to fire other events, in this case complete animations.

I want to get it to work with CSS3 :-) I hope you know what my goal is ? :) When you have the time take a look because all I get is flickering.

iamthwee - not the answer I want ! :)

Actually it does look like a nice solution and it is CSS only. The author only suggests jQuery as a way to enhance behaviou, but not a requirement.

Check the Github page for more documentation.

It is a nice solution, I want to solve this with just vendor prefixes and css, no reliance on jquery for this.

Fernado - You mentioned you were going to look at the CSS code, wondering if you will have time to get around to that ?

I will, I got sick yesterday and I'm still at work. I'll try to get to it later today.

It is a nice solution, I want to solve this with just vendor prefixes and css, no reliance on jquery for this.

The solution presented does not require jQuery, you can use the CSS file only and just add the appropriate classes to the elements. That's what the author mentions on his Github page.

It is a nice find but I'll wait until you feel better, I want to understand why it's not working with plain css3 ;-)

Take a look at this one, it's not perfect yet, but it's prooving to be a puzzle to pull off without jQuery. It isn't working on Chrome for whatever reason, I read about it and animations should be covered in webkit browsers, try to mess around with it.

JS BIN

I always use vendor prefixes with most CSS3 rules, except for some which work without.

The rotate is working, but when it rotate it should reveal the word "art/art2" this is the road block I hit as well, arghh. I don't want to use jQuery, I know you know this already :) It's just frustrating me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.