CSS Text Flip Effect? - html

It's been many a year since I used css (there was no such thing as css3 at the time) so I'm struggling to understand how, on the following page;
http://www.webdesignerdepot.com/2013/01/how-to-build-a-threaded-comment-block-with-html5-and-css3/
The red links do a sort of flip maneuver on hover, I've tried deciphering the underlying css with 'inspect element' but it's like spaghetti, I tried pasting the class in to my file and assigning it with little in the way of results.
Is there a formal name for this effect, or can anyone give me an idea as to how it can be replicated?
Thanks in advance.

class "roll-link" is doing the magic here. The transition and transform properties are doing the cool effects. When you see -webkit- and -moz- and others that means it is for those browsers because the properties are not standard yet but some browsers want to support them anyway.
/* ROLL LINKS */
.roll-link {
display: inline-block;
overflow: hidden;
vertical-align: top;
-webkit-perspective: 600px;
-moz-perspective: 600px;
-ms-perspective: 600px;
perspective: 600px;
-webkit-perspective-origin: 50% 50%;
-moz-perspective-origin: 50% 50%;
-ms-perspective-origin: 50% 50%;
perspective-origin: 50% 50%;
}
.roll-link:hover {text-decoration:none;}
.roll-link span {
display: block;
position: relative;
padding: 0 2px;
-webkit-transition: all 400ms ease;
-moz-transition: all 400ms ease;
-ms-transition: all 400ms ease;
transition: all 400ms ease;
-webkit-transform-origin: 50% 0%;
-moz-transform-origin: 50% 0%;
-ms-transform-origin: 50% 0%;
transform-origin: 50% 0%;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.roll-link:hover span {
background: #DD4D42;
-webkit-transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
-moz-transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
-ms-transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
}
.roll-link span:after {
content: attr(data-title);
display: block;
position: absolute;
left: 0;
top: 0;
padding: 0 2px;
color: #fff;
background: #DD4D42;
-webkit-transform-origin: 50% 0%;
-moz-transform-origin: 50% 0%;
-ms-transform-origin: 50% 0%;
transform-origin: 50% 0%;
-webkit-transform: translate3d( 0px, 105%, 0px ) rotateX( -90deg );
-moz-transform: translate3d( 0px, 105%, 0px ) rotateX( -90deg );
-ms-transform: translate3d( 0px, 105%, 0px ) rotateX( -90deg );
transform: translate3d( 0px, 105%, 0px ) rotateX( -90deg );
}
This part for example:
.roll-link:hover span {
background: #DD4D42;
-webkit-transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
-moz-transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
-ms-transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
}
This means that span elements inside an element with the roll-link class when hovered on will apply these styles, but will cease application of these styles when not hovering on them.
The CSS transform property is a little complicated, having several parts. A lot of guys here do not like w3schools but they are a good starting point for introductory education. http://www.w3schools.com/cssref/css3_pr_transform.asp

Following is the code responsible for the rotation:
-webkit-transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
-moz-transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
-ms-transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
Here is a working JSFiddle

Related

css transform wait until transition is completed [duplicate]

This question already has answers here:
How to use jQuery to wait for the end of CSS3 transitions?
(6 answers)
Closed 6 years ago.
I've got an element that starts out with no transforms applied to it.
After an event, the following transform is applied.
transform: rotateY( -180deg );
After another event, another transform is applied.
transform: rotateZ( -15deg ) rotateY( -180deg ) translateX( 1000px ) translateY( -600px );
Everything works fine as long as the 1st transform finishes before the 2nd. However, when it doesn't the 2nd transform will make the element do a horizontal and vertical 360.
How can I prevent the card from doing any 360 ever? and/or wait until the 1st transition is completely finished before continuing.
Full code:
HTML
<div class="studyCard">
<div class="card flip">
<input class="currentCardKey" type="hidden" value="">
<input class="currentCardPlacement" type="hidden" value="">
<div class="cardFront">
<div class="cardSub">
<p style="max-height:100px;">
<span class="frontText">FrontText</span>
</p>
</div>
</div>
<div class="cardBack">
<div class="cardSub">
<p style="max-height:100px;">
<span class="backText">BackText</span>
</p>
</div>
</div>
</div>
</div>
CSS
.studyCardContainer{
position: absolute;
width: 100%;
height: 100%;
padding: 70px 0px 90px;
z-index: 10;
}
.studyCard{
margin:0 5px;
position: relative;
height: 100%;
cursor: pointer;
perspective: 2000px;
}
.card{
width: 100%;
height: 100%;
position: absolute;
transform-style: preserve-3d;
transition-duration: .40s;
/*-o-transition-duration: .70s;
-webkit-transition-duration: .70s;
-moz-transition-duration: .70s;*/
}
.card .cardFront,.card .cardBack{
border: 1px solid #888;
background-color: #FFF;
box-shadow: 0px 2px 12px 0px rgba(0,0,0,.2);
margin: 0;
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
display: table;
table-layout: fixed;
overflow: auto;
}
/*.card .cardFront {}*/
.card.flip{
transform: rotateY( 0deg );
-o-transform: rotateY( 0deg );
-webkit-transform: rotateY( 0deg );
-moz-transform: rotateY( 0deg );
}
.card.flipped, .card .cardBack {
transform: rotateY( -180deg );
-o-transform: rotateY( -180deg );
-webkit-transform: rotateY( -180deg );
-moz-transform: rotateY( -180deg );
;
}
.card.flip,.card.flipped{
}
.card.flip.sling{
transform: rotateZ( -15deg ) rotateY( 0deg ) translateX( -1000px ) translateY( -600px );
/* -o-transform: rotateZ( -15deg ) rotateY( 0deg ) translateX( -1000px ) translateY( -600px );
-webkit-transform: rotateZ( -15deg ) rotateY( 0deg ) translateX( -1000px ) translateY( -600px );
-moz-transform: rotateZ( -15deg ) rotateY( 0deg ) translateX( -1000px ) translateY( -600px );*/
}
.card.flipped.sling{
transform: rotateZ( -15deg ) rotateY( -180deg ) translateX( 1000px ) translateY( -600px );
/* -o-transform: rotateZ( -15deg ) rotateY( -180deg ) translateX( 1000px ) translateY( -600px );
-webkit-transform: rotateZ( -15deg ) rotateY( -180deg ) translateX( 1000px ) translateY( -600px );
-moz-transform: rotateZ( -15deg ) rotateY( -180deg ) translateX( 1000px ) translateY( -600px );*/
}
.card.sling{
/*opacity: 0;*/
/*display: none;*/
transition-duration: .4s;
/* -o-transition-duration: .70s;
-webkit-transition-duration: .70s;
-moz-transition-duration: .70s;*/
}
Here was the solution I went with:
function flipCard(sideToSwitchTo){
if(sideToSwitchTo != "front" && sideToSwitchTo != "back"){
//decide for self
if($('.revealAnswerButton').is(":visible")){
sideToSwitchTo = "back";
}else{
sideToSwitchTo = "front";
}
}
if(sideToSwitchTo == "back"){
$('.card:first').removeClass('flip').addClass("flipped");
}else{
$('.card:first').removeClass("flipped").addClass('flip');
}
$('.card:first').addClass('flipTransition');
$('.card:first').on('transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd',function() {
$(this).removeClass('flipTransition');
});
}
function slingCardAway(){
if($('.card:first').hasClass('flipTransition')){
$('.card:first').on('transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd',function() {
$(this).addClass('sling');
$(this).on('transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd',function() {
$(this).remove();
});
});
}else{
$('.card:first').addClass('sling');
$('.card.sling').on('transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd',function() {
$(this).remove();
});
}
}
As noted here, you could achieve it using the following jQuery function:
$("#someSelector").bind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd", function(){ ... });
This, in this provided case, will wait for the '#someSelector' CSS animation to finish and then execute whatever piece of code you wish.
This is a possible duplicate to this and this.

How can I make this CSS only carousel show the first slide by default?

I have a CSS only carousel (which is very nice!), the only problem is that the first slide is not selected by default.
How could I achieve this without using JavaScript?
<div class="carousel">
<div class="item red slide-in" id="item1"><h1>Item 1</h1></div>
<div class="item green slide-in" id="item2"><h1>Item 2</h1></div>
<div class="item yellow slide-in" id="item3"><h1>Item 3</h1></div>
<div class="item red slide-in" id="item4"><h1>Item 4</h1></div>
<div class="controls">
•
•
•
•
</div>
</div>
And the core css:
.carousel {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.carousel .item {
position: absolute;
width: 100%;
height: 100%;
text-align: center;
}
/* animations */
.carousel .slide-in {
-webkit-transform: translate3d(-90%, 0px, 0px);
-moz-transform: translate3d(-90%, 0px, 0px);
-ms-transform: translate3d(-90%, 0px, 0px);
-o-transform: translate(-90%, 0px, 0px);
transform: translate3d(-90%, 0px, 0px);
-webkit-transition: -webkit-transform 0.5s ease-out;
-moz-transition: -moz-transform 0.5s ease-out;
-ms-transition: -ms-transform 0.5s ease-out;
-o-transition: -o-transform 0.5s ease-out;
transition: transform 0.5s ease-out;
z-index: 1;
}
.carousel .slide-in:target ~ .slide-in {
-webkit-transform: translate3d(90%, 0px, 0px);
-moz-transform: translate3d(90%, 0px, 0px);
-ms-transform: translate3d(90%, 0px, 0px);
-o-transform: translate(90%, 0px, 0px);
transform: translate3d(90%, 0px, 0px);
}
.carousel .slide-in:target,
.carousel .slide-in:focus {
-webkit-transform: translate3d(0px, 0px, 0px);
-moz-transform: translate3d(0px, 0px, 0px);
-ms-transform: translate3d(0px, 0px, 0px);
-o-transform: translate(0px, 0px, 0px);
transform: translate3d(0px, 0px, 0px);
z-index: 3;
}
.carousel .slide-in:target + .slide-in {
z-index: 2;
}
Here is a fiddle with the carousel working:
http://jsfiddle.net/kmturley/fs6wge3f/6/
One approach that partially works, would be to select the first element if it isn't a target.
To select an element that isn't a target, negate it using :not(:target).
To select the first element, just combine it with :first-of-type:
Updated Example
.carousel .slide-in:first-of-type:not(:target) {
-webkit-transform: translate3d(0px, 0px, 0px);
-moz-transform: translate3d(0px, 0px, 0px);
-ms-transform: translate3d(0px, 0px, 0px);
-o-transform: translate(0px, 0px, 0px);
transform: translate3d(0px, 0px, 0px);
z-index: 3;
}
The caveat with this approach is that the first element no longer seems to slide.
Alternatively, the only other thing I can think of would be to have an input element with the attribute autofocus="autofocus". Since the element will initially be in focus, utilize it by styling the first element using the selector .carousel input[type="checkbox"]:focus + .slide-in:
Updated Example
.carousel input[type="checkbox"]:focus + .slide-in,
.carousel .slide-in:target,
.carousel .slide-in:focus {
-webkit-transform: translate3d(0px, 0px, 0px);
-moz-transform: translate3d(0px, 0px, 0px);
-ms-transform: translate3d(0px, 0px, 0px);
-o-transform: translate(0px, 0px, 0px);
transform: translate3d(0px, 0px, 0px);
z-index: 3;
}
The caveat with this approach is that the first slide will move as soon as the hidden input element loses focus.

How to fix roll link in IE11

I use 3D roll links on my website using HTML5 and CSS3.
I'm used to make Modernizr available for IE and older browsers, but IE11 is detected as compatible with 3D css animation... and it's not.
On IE 11 :
expected :
actual result :
So the question is :
How can I use Modernizr on Internet Explorer 11? The goal is to use 3D Roll Links or fallback on non-animated CSS.
Here's my HTML's <head> :
<!--[if IE]>
<script src="js/modernizr.js"></script>
<![endif]-->
Here is the CSS I use :
/* ROLL LINKS */
.roll {
display: inline-block;
overflow: hidden;
vertical-align: top;
-webkit-perspective: 600px;
-moz-perspective: 600px;
-ms-perspective: 600px;
perspective: 600px;
-webkit-perspective-origin: 50% 50%;
-moz-perspective-origin: 50% 50%;
-ms-perspective-origin: 50% 50%;
perspective-origin: 50% 50%;
}
.roll:hover {text-decoration: none;}
.roll span {
display: block;
position: relative;
padding: 0 2px;
-webkit-transition: all 400ms ease;
-moz-transition: all 400ms ease;
-ms-transition: all 400ms ease;
-webkit-transform-origin: 50% 0%;
-moz-transform-origin: 50% 0%;
-ms-transform-origin: 50% 0%;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
}
.roll:hover span {
background: #b1162c;
-webkit-transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
-moz-transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
-ms-transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
}
.roll span:after {
content: attr(data-title);
display: block;
position: absolute;
left: 0;
top: 0;
padding: 0 2px;
color: #fff;
background: #b1162c;
-webkit-transform-origin: 50% 0%;
-moz-transform-origin: 50% 0%;
-ms-transform-origin: 50% 0%;
-webkit-transform: translate3d( 0px, 105%, 0px ) rotateX( -90deg );
-moz-transform: translate3d( 0px, 105%, 0px ) rotateX( -90deg );
-ms-transform: translate3d( 0px, 105%, 0px ) rotateX( -90deg );
}
There's a CSS trick to have a fallback with 3D Roll Links on incompatible browser. Add this to your CSS :
/* no 3d transform fix */
.no-csstransforms3d .roll span:after {
display:none;
}
.no-csstransforms3d .roll:hover span {
color:#fff;
background:#b1162c;
}
.no-csstransforms3d .roll:hover span {
-webkit-transform:none;
-moz-transform:none;
-o-transform:none;
transform: none
}
/* ie10 fix */
.no-cssreflections .roll span:after {
display:none;
}
.no-cssreflections .roll:hover span {
color:#fff;
background:#b1162c;
}
.no-cssreflections .roll:hover span {
-webkit-transform:none;
-moz-transform:none;
-o-transform:none;
transform: none
}
As you can see, you'll need Modernizr to activate this fallback, which is just a colored link. And while the [if IE] method works for Internet Explorer 8, 9, 10... it won't work on IE11. Because Microsoft thought their browser could now handle "modern" coding (and ooooh they were wrong).
So, the trick is to use javascript to load the modernizr.js if the browser is IE11. Just add this to your HTML's <head> :
<script type="text/javascript">
if(window.ActiveXObject || "ActiveXObject" in window){
<!--
var n='<script src="js/modernizr.js">';
var d='<\/script>';
document.write(n + d); //
-->
}
</script>
This will write the HTLM page differently if IE11 is detected, by adding <script src="js/modernizr.js"></script> to the code. It's simply a more difficult [if IE].
If you combine your previous CSS and HTML to this CSS fallback and this javascript for IE11 detection, you'll be fine.

Drawing an 3D Cube with Pure CSS

I would like to transform this cube, see code below, to this one which you can see on the pictures, but I don't get it.
Actual Result:
CSS
<style type="text/css">
.cube-wrap {
-webkit-perspective: 800px;
-webkit-perspective-origin: 50% 100px;
-moz-perspective: 800px;
-moz-perspective-origin: 50% 100px;
-ms-perspective: 800px;
-ms-perspective-origin: 50% 100px;
perspective: 800px;
perspective-origin: 50% 100px;
}
.cube {
position: relative;
width: 200px;
margin: 0 auto;
-webkit-transform-style: preserve-3d;
-webkit-animation: spin 5s infinite linear;
-moz-transform-style: preserve-3d;
-moz-animation: spin 5s infinite linear;
-ms-transform-style: preserve-3d;
-ms-animation: spin 5s infinite linear;
transform-style: preserve-3d;
animation: spin 5s infinite linear;
}
.cube div {
position: absolute;
width: 200px;
height: 100px;
background: rgba(255, 255, 255, 0.1);
box-shadow: inset 0 0 30px rgba(125, 125, 125, 0.8);
font-size: 20px;
text-align: center;
line-height: 100px;
color: rgba(0, 0, 0, 0.5);
font-family: sans-serif;
text-transform: uppercase;
}
.depth div.back-pane {
-webkit-transform: translateZ(-100px) rotateY(180deg);
-moz-transform: translateZ(-100px) rotateY(180deg);
-ms-transform: translateZ(-100px) rotateY(180deg);
transform: translateZ(-100px) rotateY(180deg);
}
.depth div.right-pane {
-webkit-transform: rotateY(-270deg) translateX(100px);
-webkit-transform-origin: top right;
-moz-transform: rotateY(-270deg) translateX(100px);
-moz-transform-origin: top right;
-ms-transform: rotateY(-270deg) translateX(100px);
-ms-transform-origin: top right;
transform: rotateY(-270deg) translateX(100px);
transform-origin: top right;
}
.depth div.left-pane {
-webkit-transform: rotateY(270deg) translateX(-100px);
-webkit-transform-origin: center left;
-moz-transform: rotateY(270deg) translateX(-100px);
-moz-transform-origin: center left;
-ms-transform: rotateY(270deg) translateX(-100px);
-ms-transform-origin: center left;
transform: rotateY(270deg) translateX(-100px);
transform-origin: center left;
}
.depth div.top-pane {
-webkit-transform: rotateX(-90deg) translateY(-100px);
-webkit-transform-origin: top center;
-moz-transform: rotateX(-90deg) translateY(-100px);
-moz-transform-origin: top center;
-ms-transform: rotateX(-90deg) translateY(-100px);
-ms-transform-origin: top center;
transform: rotateX(-90deg) translateY(-100px);
transform-origin: top center;
}
.depth div.bottom-pane {
-webkit-transform: rotateX(90deg) translateY(100px);
-webkit-transform-origin: bottom center;
-moz-transform: rotateX(90deg) translateY(100px);
-moz-transform-origin: bottom center;
-ms-transform: rotateX(90deg) translateY(100px);
-ms-transform-origin: bottom center;
transform: rotateX(90deg) translateY(100px);
transform-origin: bottom center;
}
.depth div.front-pane {
-webkit-transform: translateZ(100px);
-moz-transform: translateZ(100px);
-ms-transform: translateZ(100px);
transform: translateZ(100px);
}
</style>
HTML
<div id="page">
<div id="contentHolder">
<div style="height: 100px; margin-top: 40px;">
<div class="cube-wrap">
<div class="cube depth">
<div class="front-pane"></div>
<div class="back-pane"></div>
<div class="top-pane"></div>
<div class="bottom-pane"></div>
<div class="left-pane"></div>
<div class="right-pane"></div>
</div>
</div>
</div>
</div>
</div>
Demo Fiddle: http://jsfiddle.net/YT6hd/
Expected Output:
This should help, you'll have to play around with the values a little bit:
http://jsfiddle.net/YT6hd/1/
.cube.depth {
-webkit-transform: rotateY(45deg);
}
.cube-wrap {
-webkit-perspective: 8000px;
-webkit-perspective-origin: 20% 2000px;
}
Of course you'll need all the browser prefixes, I use chrome so I added -webkit-

Safari transform rotatex bug

I have a weird bug with safari...
I have 3 divs with captions, which are hidden with rotateX(-91deg). On :hover the caption comes down via rotateX(0deg). It works perfectly in Chrome etc. When i hover in safari it works only on the first div. When i hover on the 2. or the 3. the animation doesn't work.
Check out my demo: http://jsbin.com/aseced/28/edit
HTML:
<article class="tile2x1">
<section class="caption"></section>
</article>
<article class="tile2x1">
<section class="caption"></section>
</article>
<article class="tile2x1">
<section class="caption"></section>
</article>
CSS:
[class*="tile"] > section.caption {
padding-top: 20px;
width: 100%;
background-color: blue;
height: 100px;
transform-origin: top;
-o-transform-origin: top;
-moz-transform-origin: top;
-webkit-transform-origin: top;
transform: perspective( 600px ) rotateX( -91deg );
-o-transform: perspective( 600px ) rotateX( -91deg );
-moz-transform: perspective( 600px ) rotateX( -91deg );
-webkit-transform: perspective( 600px ) rotateX( -91deg );
transition: all .25s linear;
-o-transition: all .25s linear;
-moz-transition: all .25s linear;
-webkit-transition: all .25s linear;
backface-visibility: hidden;
-webkit-backface-visibility: hidden; /* Chrome and Safari */
-moz-backface-visibility: hidden; /* Firefox */
-ms-backface-visibility: hidden; /* Internet Explorer */
}
[class*="tile"]:hover > section.caption {
transform: perspective( 600px ) rotateX( 0deg );
-o-transform: perspective( 600px ) rotateX( 0deg );
-moz-transform: perspective( 600px ) rotateX( 0deg );
-webkit-transform: perspective( 600px ) rotateX( 0deg );
}
Thanks for any help.
TJL