Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
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.
For the most part, when folks talk about scaling, they are thinking of making things larger, and most of what gets scaled up are images. In this movie we are going to follow that well-beaten path, as I show you how to resize a series of images on hover. We will even toss in a box shadow for that extra 3D kick. Let's take a look at a before-and- after scenario, so you can get an idea of what we're trying to do. I have open in the browser here, the about.htm file from the Chapter 2/02_03/ about folder of the exercise files.
Right now, the four images are static, and if I move my mouse over them, nothing happens. That's fine for a nice fallback position. But let's make it a little snappier for more modern browsers, and let's switch to a final version of this. And when I hover over any of the images, they scale up 50% larger than what they were before. And when I move my mouse off the image, it scales back down to normal and the next image scales up, Hours of Fun. In this situation my HTML is just fine; all I need to work with is a CSS file, which is the main.css file.
So let's switch over to the code editor, and here I have main.css from the Chapter 2/02_03_css folder. The first thing I am going to need to do is to set up the Transitions. Instead of specifying a particular property this time, however, I am going to use a keyword, all, which will allow even the box shadow property to transition in. So I am going to scroll down to the bottom, where I have the rules I am going to need to modify, Enter.
And the first one I need to change is #theArt img tag. So again I will start out with the webkit transition. And as I said, instead of using a specific property, we will use the keyword all, and we want this to happen pretty quickly, so I am going to just put in a half second duration, .5s. And let's use the ease timing function. Okay, so I will copy that and then paste it three more times, and then adjust my vendor prefixes, replacing -webkit with -moz, the first time.
And then the second time on the third line we will replace -webkit with -o. And finally, we will get rid of it altogether. So now, let's create a rule to handle the hover state with our transforms. We will use the same basic selector ID #theArt, image tag, and to that we will add hover state. Let's start by entering in the scale function, and the syntax for that is -webkit-transform:scale.
And because I am going to scale it up in both directions at the same value, I can enter in just a single value, 1.5. Now we will increase the size of the image by 50%. So let me finish it off with a semicolon. And as we did with the transitions, we can just copy this and paste it. This time I'm going to paste it one additional time so that we can add in the prefix for Internet Explorer, which is -ms for Microsoft. So first, let's replace -webkit in the second line here with -moz, for Mozilla.
And on the third entry, instead of replacing -webkit with -o for Opera, let's use -ms for Microsoft. Now the reason we're doing it here in the transform and not in the transition is because Internet Explorer 9 actually supports transform with a vendor prefix of -ms, although it does not support transition. Let's move on and replace -webkit in the fourth line with -o, and as we have done before, let's go with our generic CSS3 property of transform by removing -webkit entirely from the final entry.
One more series of properties that we want to add to this rule, and that's the box shadow property. Again, there are vendor prefixes for this property, although not quite as many. We only to enter one for -webkit, one for Mozilla, and then the generic box shadow itself. Okay, so let's do -webkit-box-shadow, and we will offset the shadow in both X and Y directions by 3 pixels. So 3px, 3px, spread it out to 5 pixels, 5px, and give black in the color in a hexadecimal format.
So #000, close it off with a semicolon. Again, we can copy this to save a little typing and paste it in twice. As I mentioned we only need the Mozilla prefix as the second one, and the third entry is, of course, box shadow by itself. All right, let's save our file and then head back to Firefox. Let's go to our previously before figure now. And that I'll reload the page and hover over each of the images, and there is our new effect added, smooth as silk.
And by box shadow looks pretty good as well. Now before we leave this section, I want to tell you about a glitch I discovered when I was developing this particular movie. When I viewed the page in a webkit browser, either Safari or Chrome, I noticed a jump appearing at either end of the scaling. First, when it gets large and then again, when it returned to its original size. Now we are not seeing it now because the browsers have been updated, but this effect definitely appeared in earlier versions of the webkit browser.
So I was forced to find a solution for that. The solution is applying the webkit backface-visibility property. As discussed in the chapter on 3D Transforms, this property toggles the rendering of back size of 2D elements. Luckily, it also has the desired effect in the 2D environment. So, in order to fix this issue for backwards compatible browsers, we will need to add one more bit of code. Here in my hover state, I will press Return to make space for one more entry and enter in webkit-backface-visibility: hidden.
And again, for earlier versions of the browser, which you may or may not have installed, you don't need to do other vendor-specific entries for it. Okay, our scaling project is complete, but before we go, let me leave you with two thoughts. First, for optimum image results, you want to create your images in their final scaled up size and then insert them with reduced width and height for the smaller thumbnails. And second, keep in mind that scaling isn't just for images; you can also apply to page sections, like the sides to give them emphasis, or even Submit buttons, to encourage people to click.
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.