Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
CSS: Page Layouts introduces basic layout concepts, gives advice on how to create properly structured HTML based on prototypes and mockups, and goes into critical page layout skills such as floats and positioning. Author James Williamson shows how to combine these techniques to create fixed, fluid, and responsive layouts. Designers are also shown how to enhance their pages through the creative use of CSS techniques like multi-column text, opacity, and the background property. Exercise files are included with this course.
Rounding corners used to be something that every designer had a specific technique to achieve. Pure CSS rounded corners weren't possible in the past, so people created images, used transparent GIFs, nested div tags. There were a ton of different methods that people would use. Now with the adoption of the recent border-radius property and its widespread support within browsers, it's as simple now as declaring a single property. So we are going to talk about the border-radius property. It can accept either length or a percentage value, so you can say I want it to round by 25 pixels, or I want to round it by 10%.
Now if you use a single value, all corners are rounded equally. For more than a single value, when you use the border-radius shorthand, it gets a little convoluted. So what we are going to do is we are going to go through all of the options for the syntax--and there are a quite a few of them--and then we are going to talk about ways that you can sort of creatively use border-radius to create some custom shapes. So I am going to go into our HTML page that we are going to be using for this one, is border-radius.htm, which is found in 08_03 directory. There is, if I scroll down into the code, just one section down here, with a paragraph in it that says, "round my corners, please." So that is what we are going to do.
So I just want to go up to the section selector right there, and just below all the rest of them, I am going to go ahead and declare a border-radius. And why don't we do 25 pixels? We just start off with that. So if I save this, go back into my browser and refresh the page, I can see that I have rounded corners on all four sides of about 25 pixels. So when you use a single value for border-radius, it goes ahead and applies it all equally to each of the corners. Now if I use more than one value--I don't use commas to separate them.
I just use the whitespace. I'll come in and say, 10 pixels here for the second value. Now I will save this and I'll preview this again in the browser and you can tell the difference right off the bat. So what's happening here is border- radius is applied in a clockwise fashion, but it starts in the top left-hand corner. So the first value is top-left. And when you use two values, essentially the opposite corner is applied as well. So you can see top-left and bottom-right both have 25 pixels. top-right, which is the next value, and its opposite corner, bottom-left, get the 10 pixels.
So, it goes 25, 10, 25, 10 based on syntax. Now what if you used three values? So after the 10 pixels, I am going to go ahead and do 5 pixels. I am going to save that, preview it in my browser, and you can see what happens is that the first value, top- left, gets 25 pixels; the middle value is used for both the top-right and the bottom-left; and then the third value is used for bottom-right. So it's still going in sort of that clockwise fashion; just the middle value is being used for two corners instead of one. And then, if you use all four, so let's say I go zero on the last one, save that, it's just going to go ahead in a clockwise fashion.
So you can see it starts at the top- left now with 25, then it goes to 10, then it goes to 5, and then finally on the bottom-left-hand corner, it goes to zero. So I love having that ability to independently control corners, because you can do some really interesting things when you're styling your container elements with that property. Now if you only want one corner, you don't need to use that shorthand notation. So let's go back into our code. I am going to get rid of all of the values except for 25 pixels, and then for our border-radius, I am going to change that property. I am going to change it to border- top-left-radius, so border-top-left.
As you can imagine, you could also do top-right. You could do bottom-left, bottom-right. And if I save this and I preview it, you can see that now it just isolates that corner radius to the one corner. Now even in this particular syntax where we are addressing a single corner, you still have options. For example, if I pass two values into this, let's say I do 25 and I do 15 pixels, and if I save this, and preview it, what's happening is the top-left-hand corner is getting 25, the bottom is getting 15.
So what it's allowing you to do is actually do unbalanced rounded corners. And if you've ever worked with a vector- based drawing program like Illustrator, for example, and you've used Bezier handles where you have a point and you have the handles coming off the point, this is essentially the same as being able to control each of those handles individually, which is a really, really powerful feature. Now you can use the shorthand syntax to have unbalanced corners as well. If I go back to just doing border- radius, so not top-left, but just border-radius, if I were to pass this syntax in, we know that this is going to affect all four corners, and it's going to apply the first value of course to the top-left, bottom-right, and then the second value 15 pixels is going to go to top-right and bottom-left.
But if I change the syntax and I put a forward slash between the two of them, now if I save this and I test it, you can see I am getting unbalanced corners now all the way around. And the 25 is being used for the tops on the tops, and it's being used for the bottoms on the bottom, so it kind of flips if you are going to be doing it that way. You can go ahead and write that syntax out as long as you wanted to. Now once you understand how this works, you can do some really interesting things, because you can use different values.
For example, let me show you. Let's say, for example, I did 120 pixels and then followed that up with 10 pixels. Now you can also do negative. So if you want to create curves to sort of curve back on themselves, you can certainly do that. I have seen people draw hearts and things like that using this technique. So let's say I do 120 for top-left and 120 for bottom-right using this syntax, and then I am doing 10 pixels for top-right, bottom-left. But then I come over here and I just go backwards. I do 10 pixels for the opposite side of the same corner, and then I do 120 pixels for the opposite side of the other corner.
So, if you can envision this in your head again, the top-left-hand corner would be 120 pixels rounded on top, and then it would be 10 pixels on the bottom. And the other corners are going to be opposite of that. So if I save this and I go back into the browser and refresh it, you can see that what it gives us is kind of a custom shape. It looks almost like a piece of paper with the corners bending based on the flow of the paper. So the more you experiment with these different values, the crazier shapes you get to control and create. And it just takes a little bit of work to get used to handling all the different radiuses, especially if you are going to pass in sort of unbalanced values.
But once you experiment with it just a little bit, you will get comfortable with it very, very quickly. So I encourage you to go out and experiment with border-radius. Rather than simply rounding your corners on your elements, which is valuable in its own right, experiment with some of the settings, get comfortable with them, and then begin creating your own custom shapes.
There are currently no FAQs about CSS: Page Layouts.
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.