Start learning with our library of video tutorials taught by experts. Get started
Viewed by members. in countries. members currently watching.
With robust and ever-increasing browser support, it is now possible to take advantage of expressive CSS3 capabilities across modern browsers. In this course, Joseph Lowery explores the possibilities of the new coding options, which animate well over 50 different properties automatically or interactively, and how they open the door to enhanced user experiences. This course covers the range from simple to complex transitions, including 2D and 3D transforms, and illustrates how transitions are expedited in various web authoring tools, as well as Dreamweaver. The course also contains a start-to-finish interactive slideshow project that allows you to practice and see the transitions and transforms immediately in action.
But instead of showing the painting in reverse, related secondary content is displayed. And when I move off one painting and on to another, the first one reverses its card flip, while the second one flips over. So as you move around, you get a nice little card flip dance going on. Now if we take a look at the page in a non-supporting browser, you'll see the same content, but instead of a 3D flip, you get a 2D slide. How is that for a graceful degradation? Let me show you how it's all done.
Browsers that can, will get one set of classes added to specific div tags that will flip the initial content away and flip in the secondary content. While browsers that don't support CSS 3D transforms will have the content animated from the bottom up. So right below those three includes I have a script tag that contains the functionality that handles this code swapping. Let me scroll down just a bit. The opening statement on line 20, if ($('html').hasClass('csstransforms3d')), checks to see if the browser supports the property, and if so, it removes the Class slide, as you see on line 21, and substitutes flip.
Then, if selector with the flip Class is hovered over, it toggles between adding the class "theFlip" and removing it. Now if the browser does not support the csstransforms3d property, the function that starts on line 31 kicks in. Here, the slide class is left in place and a slide up animation is toggled on and off. Now before we get to the CSS, I want to show you the HTML structure of each of the artworks. So let's scroll on down, I'll go down to around line 76 or so, and the div with the ID of theArt is where there is a group of four slides.
For each slide, both the image and its description are nested under a div with a class of artGroup and the default class of slide. The code for the image like that found on line 78 is placed in front of the div with a class of details, line 79, that contains the image information. We're ready to tackle the CSS necessary for both the 3D transform and the sliding animation for older browsers. Let's switch over to transitions.css that's found in the _css folder, and I'll scroll down to the bottom, create a few empty lines to bring our code up. Let's enter in the CSS rules we'll need for the older browsers first.
And I am just going to put in a little comment here. The first one is the class of artGroup with another class of slide. And all we need to add here is the property overflow set to hidden. Now we need to create a class that positions the detail content so that it's out of view. So again, we'll target artGroup.slide, and then within that the class of detail.
All of my images are of the same size, so I can use one value here, so let's set bottom to -364 pixels. Okay, that's all we need to do for the older browsers. So for newer browsers--that's the main event--let's add the CSS necessary to make the card flip happen. In all, we'll need just four rules. First, since this is a 3D value we're working with, let's set up our 3D by adding a perspective attribute to the general image and details container, which is called artGroup that has the class of flip.
This will ensure that the children of this div will exist in 3D space. And we'll start with the -webkit-perspective property. Let's set it to a value of 800 pixels. It's kind of a medium value that should ensure no distortion. And now I am going to copy my -webkit-perspective value, paste it in three times, get rid of that extra space I put in there by mistake. And let's change the second entry of -webkit to Mozilla, -moz, the third one to -o for Opera, and let's get rid of it for the fourth one altogether.
Perspective is done. Next we want to target that child, which is the class artwork and set up the transition for the transform property with a brief duration. Again, I'll enter the selector artGroup flip, and now we'll do the second class we want to target, which is artwork, and this is the individual paintings. First we'll set up our transition for the transform property, and as always we'll start with -webkit.
Name the property we want to transition, which is transform, but of course, since this line is vendor-specific we have to add in that prefix as well. So -webkit again, -transform and the duration of 1 second. We'll leave off the timing function, and that will revert to using the default value, which is ease. Okay, let me copy and paste our transition statement, make the necessary changes, and that section is done.
Next, because perspective on the parent element only pertains to the direct children--which here is the class of artwork--we want to use the transform style property set to preserve 3D to pass that perspective along to the next level of children, which will be the image and the details. I get a little error here just to make it clear what we are doing, so we'll enter in -webkit-transforms-style, and set that to its value of preserve-3d.
Okay, that is eminently copyable, and equally replaceable, so let's make those alterations, and now that bit of code is done. Now let's add in the actual 3D transform using the rotateY property. Set to spin 180 degrees in a right to left direction-- that will be a negative direction. We'll specify two selectors, one for each face of the card.
First we'll do the detail, and that will add in the image itself. So let's enter in our -transform: rotateY property, starting with the -webkit version, and we want this to go -180 degrees I'll do my copy/paste routine. Finally, we need to make sure that when the card is flipped, the other side does not show through. For that we'll add the backface visibility property with the value of hidden, and this goes on to a rule targeting the image and the detail.
So -webkit-backface-visibility:hidden, select, copy, paste. And changing those prefixes one more time, we are going to save the file now and then let's go take a look at it in the browser. So here I have opened the about.htm file, and when you first look at it before I refresh the page, you see the details showing up, and that's because we didn't have the opacity in place.
There are currently no FAQs about CSS: Transitions and Transforms.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.