Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
As CSS expands its technical proficiency, more dynamic possibilities emerge. With the CSS3 Transform features you can move page elements, scale them and as you're about to see, even rotate them. Web pages aren't just for 90 degree rectangles anymore. Let me demonstrate the type of effect that you can get by switching to the final example page, so keep your eye on these two callouts here. When I switch to the final page, they rotate counterclockwise and I'd even add a little drop shadow just to make them really pop.
Alright, let's take a look and let me show you how it's done. So I do have open here the mission.htm file located in the Chapter 6 > 06_03 folder, and the first thing I want to do is identify my callouts here. So I'll put my cursor in there and I can see I have a callout with an ID of trivia and if I put my cursor in the one on the right, there is also a div with the ID of join. So I'm going to want to create a CSS rule that targets both of these callouts to get them to rotate equally.
So let me close off my Files panel. Okay, we're ready to write out our CSS rules. To do this, it's actually better for us to go right into the main.css and write out the code by hand. So I'm going to put this all the way down at the bottom and move my Split view, so that I can make sure that I'm targeting the correct callout boxes. So the first one is a div with a class of callout and an ID of trivia. So we'll put that in, div.callOut# trivia, so we can add in our second one.
And then let's take a look at what that is, and here we can see that there is also div.callOut, but it has an ID of join. Alright, our open curly brace and let's close off. So now we're going to put in the CSS transform property that will rotate these two divs, and because we're on the cutting edge of browser support for this, we'll need to put in some vendor specific properties first.
We'll start off by doing the Microsoft version, which is -ms, and you can see that the code hints are right there with us helping us. After I put in the second hyphen, I'll see all of the available properties, and I'll put in a tr for transform, and there's my transform. So after I hit Return, Dreamweaver puts in the rest of the word transform and adds a colon and now we want to type in rotate and you can see it right there. So I'll just type the first letter r and then hit Enter or Return, and within the parentheses I want to put the amount that I want to rotate.
In order for me to go counterclockwise, I'll need to put in a negative sign, and I'm just going to a slight amount. I'm just going to 5 degrees, so you enter in the value of 5, and then keyword deg, short for degrees. Okay, let's go to the end of the line and close that out with a semicolon. Next up, let's do one for Safari or WebKit. So -web, and then I hit Return and then it adds Webkit. Similarly we'll do transform.
After I've hit Return, I can type in ro for rotate and it's the same value 5deg, and close out that one. Next, let's do Opera, also transform, also rotate. So this time I'll go ahead and put in my semicolon and then move into position in between the parenthesis and add in the 5deg value. Okay, the last vendor specific one is for Mozilla, so it's a -moz, and again, transform and again rotate.
Now to make sure that we're forward compatible, we're going to go ahead and just enter in the generic version, which is just like all the others; transform:rotate(-5deg). So that should be it. If I click over into Live View, it should immediately update and there you can see my two divs rotating 5 degrees. If you wanted to take a look at a different value for them, you can go ahead and just change the WebKit version, because we are of course working with the WebKit in Live View.
So let's make it 50 degrees negative instead, and when I switch over you can see a much more radical change. That's a little bit too much for this particular client, so let's go back to 5 degrees. Now to really make them stand out, we're going to go ahead and add a drop shadow to this. So after that final transform rotate, hit Return to enter a new line. And we only need to do a couple of vendor prefixes for this, only WebKit and Mozilla. So we'll do WebKit first. -webkit-box-shadow and this is very similar to the text shadow values that you saw in the Applying CSS3 Text Shadows video, also in this chapter.
In this case, let's do an X offset of 2px, and then a Y offset of the same value, 2px. A blur radius of 5px and a dark gray color, #666. Okay, I'll close that off with a semicolon, and let's do the Mozilla version. -moz-box-shadow and then the same values, 2px, 2px, 5px and #666 for the color.
And finally, we'll put in the generic CSS3 version: box-shadow: 2px, 2px, 5px, 666. Now when I click into Live View, you'll see a pretty subtle drop shadow added, and let's get out of Split view, so you can see it fully. You can rotate pretty much any HTML element, whether it's a div containing text as we did here, or a heading, or a paragraph, all by itself.
Get unlimited access to all courses for just $25/month.Become a member
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.