Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this course, we are going to focus on building three main types of layouts: fixed, fluid, and responsive. Now I have got examples of all three of those layout types open here, and I want to go over the basics of each of them, as a way of introducing these layout types. So we have got fixed.htm, fluid.htm, and responsive.htm, those three files, open. I have opened them from the 01_09 directory. Now before we preview these in the browser, before we go into the CSS and take a look at the actual concepts that's driving the different types of layouts, I want to go over the structure of the actual HTML. So I am in fixed.htm and if I scroll down into the body of this document, I can see that the page starts with a header that has the headline Alice in Wonderland, and that's followed by an article which contains some of the opening part of the Alice in Wonderland novel.
And then if I go down a little bit further, I can see that I have it an aside pass the article, and this aside has a personal note from Lewis Carroll in it. And at the very, very bottom we just have a simple footer. Okay so that is the structure that is used throughout all three of the pages. So the only thing that's going to change when we preview these pages in the browser and we take a look at how they respond to changes within the browser, it's important to remember that the underlying structure of the page of HTML is exactly the same. Same class attributes, same structure, same elements; nothing changes other than the CSS.
Okay, so we are going to start with the fixed.htm. So I am going to go over to browser and preview that page. And here we have our layout. Here is our header. We have got a simple two-column layout. If I scroll down, we can see at the very bottom there is our footer down there. So very simple page structure, but this is a fixed layout. Now that refers to the fact that it is set to a fixed size. So any change I make to the browser--I am just going to resize my browser window here--does not affect this layout at all. It remains consistent no matter what device, not matter what user agent, no matter what screen size this is viewed at, it always stays the same because it is fixed to a very specific size.
Now if we take a look at the CSS for this page, we can see that it does not take a lot to accomplish this. If I scroll down, as a matter of fact, I can see in this body selector here the page is being set to a width of 960 pixels. So we are using absolute length values for these measurements. And if I go down into the actual layout styles for these three sections, the article, aside, and footer, you can see that we are using floating to move elements from one size to next. We have an entire chapter on floating command. But more importantly, the width values here, each one of these is giving a very explicit width value that's telling it how much space within that fixed size those elements should take up, so that is a fixed layout.
Okay I am going to switch over the fluid layout now and preview that in the browser. And now you can see, probably at first glance, there is little something different about this page. It appears to be occupying a bit wider space, so it looks a little bit wider than our previous layout. Same basic concept in the layout. We have two columns. The main content is on the left-hand side, the note from Lewis Carroll is in the right-hand side, and of course we have our footer down in the bottom. So what is so different about a fluid layout? Well, unlike a fixed layout which remains fixed based upon a specific size that you set on the page, fluid layouts do respond to changes made in the user agent or the browser.
So as I resize the browser, you can see that the layout changes as well. Now it stays a two-column layout, but essentially each of these sections is taking advantage of the available space. So the upside of this is no matter what size this is viewed within the browser, we are still going to get our two-column layout. We are not going to have any horizontal scrollbars or content cut off, but the downside is is when you start getting to the extremes, you can see that the layout starts--really has a hard time holding up with this. And actually what I've done here is I have some minimum width values set on this, so that it wouldn't even go further than this.
And the other thing is that at the other extreme, when we start taking it really, really wide, some of the content begins to get maybe a little bit wider than we'd like for it. There are of course minimum and maximum width values that we can put on our elements to prevent this, but that's one of things that you have to aware of with flexible layouts. Now if I go back into the CSS of my fluid layout here, I can see that again the body has a width value set, but this time instead of an absolute value, we are using percentages, so at this point we are just saying hey, go ahead and let this page take up 85% of the available space within the browser.
If I go into the individual layout styles of these, I can see that again, we are using percentage values for widths and padding as well so that each one of these elements is occupying a specific amount of space based on a percentage of its parent. So while you're not really sure exactly how much space each of these elements is going to take up, you understand that the relationship between the two of them will remain consistent, regardless of how much space is available, because of the percentage values that you're setting on these. Okay now let's go ahead and take a look at responsive layouts. So I am going to switch over to the responsive.htm, and I am going to look take a look at that in the browser first.
Now responsive layouts are very similar to fluid layouts in the fact that they do respond to various things. One of the things that they can respond to, and the thing that we are going to demonstrate here, is the size of the browser window. They can then also respond to different things, for example, the orientation of the device. Responsive layouts can, if a device is in portrait or landscape mode, for example, the height of the device. So there are a lot of different things responsive layouts can respond to. So in this case, you will notice that initially we actually have a three-column layout based upon the available size. So our main content area has a two column layout, and we also have the aside still here.
We notice that our sections have a little bit of a separation between them in this particular layout, and we have a footer down here as well. All right, so if I resize this, at first it looks really no different than the fluid layout. It's just changing based on size. But I also notice that this appears to have a range. So when I get down to this section, it stops flexing. And if I keep going down, I reach a break point and when it hit the break point I get sort of an entirely different layout. You will notice, for example, the heading changes in size. You will notice that the column over here is now single column instead of a double column.
We don't have the visual separators at the end of the section anymore, so all of those change. And you can have as many of those break points as you want or need within a layout. So when we get down to another certain break point, instead of remaining a two- column layout, it goes down to being a single-column layout and in this case again a lot of things changes, like the size of the headings, the text size changes a little bit. We now get a separator above the aside and below the article, and then our footer changes a little bit as well. Now, responsive layouts are relatively new in terms of a layout concept.
It's designed around the way that people are now consuming content online, which is to say, using multiple devices. So here we have a layout that's adapted for the screen we have one that's adaptive for tablets, and we have another one, a smaller single-column layout, that's adapted for phones. Let's take a look at the CSS and see how that's actually accomplished. So if we go back to the CSS and start towards to the top of it, you can see in the body selector here, for example, there's no width specified here. Really the only thing that this is a accomplishing is centering the content on the page, in terms of layout. It continues for a while. There is no layout styles, so where have all those layout styles gone? All right, so if we go down to about line 74 or so, we can begin to see the layout styles and the inner rule that you may or may not have seen before.
This is called a media query, and we have an entire chapter on response layouts, and we are going to talk about media queries in more detail. But essentially what media queries allow you to do is filter which styles are applied based upon the media query. So if these conditions are met, the styles contained within it are served, but if they are not met, they are not served. Now this allows you to present in this case pretty much three different layouts. So here we have styles that apply only if the minimum width is 780 pixels, so this would apply to any screen size of 780 pixels or greater.
Now you will notice that we are using percentages. So this is more of a flexible or fluid layout, but we do have minimum and maximum widths, so that's basically giving it a range of measurements that you can flex inside of, but then it will sort of freeze in those positions if it's above or below those values. Now if I keep going down, I can begin to see each of these media queries. This one, for example, goes between 481 and 780 pixels, so that's for tablets. And if I just scroll down a little bit further, I can find anything that's below 480 pixels, and that would be a smartphone.
So that is a brief overview of fixed, fluid, and responsive layouts. I don't want to imply, or I do want to make it seem from this movie, that there are only those three types of layouts. For example, we didn't even talk about elastic layouts, which are layouts that are totally based on ems. Nor did we discuss how some designers just mix techniques from various layout types into hybrid layouts. Now in fact, you could argue that there aren't really types of layouts at all; there is just a mixture of techniques that results in the desired page design in the layout's behavior.
Now that's what I am focusing in this title first on the layout techniques that we are going to be learning and then how to use those techniques to create a specific layout type. And I want to make sure that you understand that the layouts you build should conform more to the needs of your site than the rules of any one specific layout type.
Get unlimited access to all courses for just $25/month.Become a member