Start learning with our library of video tutorials taught by experts. Get started

CSS3 First Look

Using 2D transforms


From:

CSS3 First Look

with James Williamson
Expand all | Collapse all
  1. 3m 5s
    1. Welcome
      1m 20s
    2. Using the exercise files
      1m 45s
  2. 31m 30s
    1. What is CSS3?
      5m 26s
    2. The current status of CSS3
      3m 35s
    3. An overview of CSS3 capabilities
      2m 24s
    4. Can you use CSS3 now?
      5m 31s
    5. Detecting support for CSS3
      9m 0s
    6. Understanding vendor prefixes
      5m 34s
  3. 1h 9m
    1. An overview of child and sibling selectors
      3m 11s
    2. Using child and sibling selectors
      7m 17s
    3. An overview of attribute selectors
      3m 19s
    4. Using attribute selectors
      8m 32s
    5. Pseudo-class UI selectors
      5m 56s
    6. Negation pseudo-class selectors
      6m 48s
    7. Target pseudo-class selectors
      5m 39s
    8. Structural selectors
      3m 58s
    9. Nth-child selector syntax
      10m 0s
    10. First, last, and only structural selectors
      5m 39s
    11. Using structural selectors to write more efficient code
      8m 52s
  4. 45m 28s
    1. Color formats in CSS3
      7m 9s
    2. Transparency in CSS3
      9m 10s
    3. CSS3 gradients
      4m 11s
    4. Creating linear gradients
      13m 57s
    5. Creating radial gradients
      11m 1s
  5. 49m 8s
    1. Working with web fonts
      6m 38s
    2. @font-face syntax
      4m 52s
    3. Downloading sample fonts
      6m 5s
    4. Writing @font-face declarations
      7m 57s
    5. Using web fonts
      6m 42s
    6. Using text shadows
      7m 14s
    7. Creating multi-column text
      9m 40s
  6. 50m 55s
    1. An overview of the flexible box model
      4m 42s
    2. Controlling box orientation
      5m 2s
    3. Setting element flexibility
      12m 59s
    4. Distributing boxes
      7m 54s
    5. Controlling box alignment
      12m 38s
    6. Working with box-sizing
      7m 40s
  7. 1h 5m
    1. Using border-radius
      6m 20s
    2. Creating custom rounded corners
      10m 21s
    3. Understanding border images
      5m 15s
    4. Using border images
      8m 52s
    5. Creating box shadows
      8m 58s
    6. CSS3 backgrounds
      4m 55s
    7. Controlling background size
      8m 46s
    8. Creating multiple background images
      6m 4s
    9. Using background-origin
      3m 18s
    10. Clipping background content
      3m 2s
  8. 40m 8s
    1. An overview of CSS3 2D transforms
      4m 26s
    2. Using 2D transforms
      8m 16s
    3. Setting transform origins
      5m 24s
    4. An overview of CSS3 transitions
      5m 0s
    5. Animating CSS properties
      6m 12s
    6. Using easing in animations
      5m 41s
    7. An overview of 3D transforms
      5m 9s
  9. 37m 56s
    1. Understanding media queries
      6m 18s
    2. Strategies for targeting multiple devices
      6m 4s
    3. Writing styles for target screen sizes
      12m 11s
    4. Deploying styles through media queries
      3m 55s
    5. Basing media queries on page orientation
      2m 24s
    6. Targeting media queries for iOS devices
      7m 4s
  10. 1m 6s
    1. Goodbye
      1m 6s

Video: Using 2D transforms

The CSS required to apply transforms is deceptively simple. In just a few lines of code, you can make dramatic changes to elements on the page. However, there are a few rules regarding how transforms are applied that you need to be aware of. We'll discuss those concerns, as well as explore the various options that we have when transforming elements as we begin to modify a photo gallery that will eventually use transforms and transitions to create a more compelling user experience. So just so you know where we are going to eventually end up, I want to show you the finished gallery first.

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
Please wait...
CSS3 First Look
6h 34m Appropriate for all Nov 29, 2010

Viewers: in countries Watching now:

In CSS3 First Look, staff author James Williamson provides an in-depth introduction to the newest CSS standard, detailing its modular format, history, and current level of browser support, while also demonstrating its capabilities and applications. The course includes tutorials on using new selectors, modifying typography and color, working with the box model, and understanding media queries. Exercise files accompany the course.

Topics include:
  • Understanding the history of CSS3
  • Working with the new selectors
  • Adding transparency and gradients
  • Specifying web fonts with @font-face
  • Understanding the advances to page layout
  • Looking at CSS3 box model capabilities
  • Using 2D and 3D transforms
  • Understanding media queries
Subject:
Web
Software:
CSS
Author:
James Williamson

Using 2D transforms

The CSS required to apply transforms is deceptively simple. In just a few lines of code, you can make dramatic changes to elements on the page. However, there are a few rules regarding how transforms are applied that you need to be aware of. We'll discuss those concerns, as well as explore the various options that we have when transforming elements as we begin to modify a photo gallery that will eventually use transforms and transitions to create a more compelling user experience. So just so you know where we are going to eventually end up, I want to show you the finished gallery first.

In this exercise, we're really just going to be experimenting with some transforms, but just so you have an idea as to what we are going to be doing is eventually our gallery will do this for us. So we are going to have some thumbnails that to do some transforms and some transitions to get a little bit more information about that particular photo, which is cool. Okay, so we'll get there eventually, but in this lesson remember we're just going to focus on experimenting a little bit with transforms. So of this exercise, I have the gallery.htm opened up and we'll be working on this file as well as the CSS.

Now, if I scroll down, I can find my gallery down here on the bottom and we are not going to spend a whole lot of time with this. I just want you to understand the structure. So the thumbnails are contained within a div tag with an ID of thumbStrip. Then the thumbnails themselves are in a div with a class of thumb. So that what we will be controlling as we write our selectors. So I'm going to switch over to the main.css file. Again, you can open that up separately or if you're using a program like Dreamweaver, you can just simply switch over. What I want to do is I want to scroll down to about line 937.

So I am going down towards the bottom there, there we go. I can find a couple of selectors in this area. One is the thumbnail itself and then the other one is a hover element. Now, I am going to apply the transforms to the hover pseudo-selector. Now why am I doing that? Well, I want us to be able to really see the difference between the pre-transform state and the transform state. You don't have to make user interactivity part of a transform, but it can be. In this case, I'm doing it on purpose, because I want us to see the before and after, and hover gives us a really nice ability to do that.

Okay, so here's what we are going to do. I'm going to place my cursor directly in the thumb:hover pseudo-selector and we're going to do our transform. So I'm going to do a Mozilla first, so moz-transform. And again, I mentioned that the syntax is just deceptively simple. We can pass a scale to it and we could scale that up by one-and-a-half times its current size. So all these transform functions you just pass in the value that they need. Some of them need lengths. Some of them need just multiples as we have in scale here, and some of them need degrees such as rotation and skew. So you have to know what they're looking for.

So we are going to go to WebKit here and then just the general generic transform as well. We are going to keep that syntax throughout the title. So I am going to go ahead and save that, preview that in any browser, Chrome. I'm going to keep with the WebKit browsers for these transforms, because again their implementations are a little further along. Now notice that when I hover over these images, they're scaling up. It really is that simple. That's pretty amazing. All right, let's take a look at some of the other transform functions that we can use. I am going to close this and go back into my code. I'm going to replace scale with rotate.

So I'm going to go ahead and rotate this and rotation requires degrees. So I'm going to pass 45 degrees in. Again, I'm a big fan of copying and pasting, so that I don't have to type that three times. There we go. Save that. I'm going to test it again. Now as I hover over them, they're rotating by 45 degrees. So you can really see the before and after with those. That's pretty cool. Let's keep going. Let's try some of the other ones. We're going to do skew next. Now skew, just like rotate, skew also requires degrees.

We are going to skew it maybe not quite as much. With skewing, I found a little goes a long way. By the way, I think I need to point out something here. When you rotate something, the degrees move it in a clockwise fashion, but when you skew something, the degrees move it in a counterclockwise fashion. So I'm going to save that, preview it, and notice that we get a little bit of skew action going on. You can see what I mean by a little goes a long way, as I hover over the thumbnails. Cool! One more transform function that we haven't tried yet, and that is translate. Translate is just another way of saying offset and there are various ways to do this.

You could, for example, use relative positioning and do an offset, but translate works really well. So with translate, you can pass multiple values. In this case, I'm going to pass 10 pixels and 10 pixels. Essentially, what that's going to do for me is it's going to move it 10 pixels over to the right and 10 pixels down. So again, I'm going to copy that, paste it a couple of times and I should be good to go. So we'll save that again, preview that in our browser and now we can see indeed, it's moving down and to the right. Cool! Now remember you can also, if you want to, a lot of these values such as skew and scale and translate, you can add on an X or a Y to those values to make sure that they're only happening along one axis.

Let me show you what I mean. I could change this one for example to translateY, and there's always a capital letter, X or Y. Then I only need to pass in one value. Positive values move me down the Y axis. Positive X values move me to the right. So again if I wanted to go up or to left, I would use negative values. Preview that again and now notice that it's only moving in one direction, which is really, really cool. You can also combine effects if you'd like. Now when you combine effects, there are a lot of things that you need to concern yourself with, but let's combine some effects first and then I'll talk about those.

So I am going to replace this translate. Actually you know what, I'll leave the translate on there. After the translate is over, I'll do a space. So these are not comma-separated; they're single spaced. I'll do scale, 1.5, then another space and then rotate that by about 15 degrees. So essentially, I'm just combining all of the effects together. I'm going to move it down by 10 pixels. I'm going to scale it by one-and-a-half times its normal size and then rotate it 15 degrees while I'm at it. So I'm just going to go ahead, copy that, and paste that and all of those, then we save that and test that again.

Now notice that we have multiple transformations applying to this. That's really cool. Nifty! Now when you apply those multiple transformations, you need to be really careful and let me show you why. First, let's say I do a skew and skew and rotate are the ones you really have to look out for. Let's say I skew something by 15 degrees and then I rotate it by 45 degrees. Again, I'm just going to copy this and paste it into the rest of these.

So these effects are basically applied in order. As they are applied in order, certain effects really matter where it comes in that stage. And let me show you what I mean. So here we're just seeing a rotation, but notice the skewing is having a very different effect. It's not really skewing it as much as it is basically just distorting the image to a new aspect ratio. On the other hand, watch what happens if we flip these. So let's say I take skew and place it on the other side of rotate. I'm just going to do that a couple of times.

All right, let's try that. I'm going to save that, preview it, and we can see we are getting a very, very different effect. So, the order in which you combine those effects together really matters. Remember they are going to be done in order. This one for example is rotating at first and then skewing the results, which gives you a very different result than skewing it first and then rotating the skew. So be really careful and aware of that as you are combining these guys together. As we've seen, they're very easy to apply.

We can combine multiple transforms and create these really complex transformations for elements on the page, but we do need to keep in mind when we combine those effects, the order in which we specify them can have really dramatic effects on the overall transformation. So you're going to want to test that early before using any type of a combination. So in our next movie, we're going to explore how to take even more control over our transforms through the use of transform-origin's.

Find answers to the most frequently asked questions about CSS3 First Look.


Expand all | Collapse all
Please wait...
Q: I'm following along with the video "Transparency in CSS3".  James shows us how to achieve transparency in Internet Explorer by going to Kimili.com and entering a HSLA value to generate code for transparency.

Here that code:

background: transparent;-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#BF0E0C0B,endColorstr=#BF0E0C0B)"; /* IE8 */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#BF0E0C0B,endColorstr=#BF0E0C0B); /* IE6 & 7 */ zoom: 1;

When this code is added to my HTML file it removes transparency on browsers that do in fact support it. So I'm left with NO transparency. Why?
A: The problem is in the filter code. If the IE background is called last, the first "transparent" declaration will remove all previous colors, regardless of browser. To resolve this, place the rule inside a conditional comment for IE or remove the "transparent" declaration at the front of the rule.
Share a link to this course
Please wait... Please wait...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed CSS3 First Look.

Return to your organization's learning portal to continue training, or close this page.


OK

Course retiring soon

CSS3 First Look will be retired from the lynda.com library on April 24, 2014. Training videos and exercise files will no longer be available, but the course will still appear in your course history and certificates of completion.


Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked