Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Growing page elements

From: CSS: Transitions and Transforms

Video: Growing page elements

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.

Growing page elements

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.

Show transcript

This video is part of

Image for CSS: Transitions and Transforms
CSS: Transitions and Transforms

26 video lessons · 15101 viewers

Joseph Lowery
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

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.


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.

Join now Already a member? Log in

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 CSS: Transitions and Transforms.

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


OK
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 preferences from the dropdown menu.

Continue to classic layout Stay on new layout
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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

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
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.