New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

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

Fixed, fluid, and responsive layouts

From: CSS: Page Layouts

Video: Fixed, fluid, and responsive layouts

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.

Fixed, fluid, and responsive layouts

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.

Show transcript

This video is part of

Image for CSS: Page Layouts
CSS: Page Layouts

71 video lessons · 40101 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 4m 20s
    1. Welcome
      54s
    2. How to use the exercise files
      3m 26s
  2. 1h 39m
    1. Box model review
      8m 47s
    2. Calculating element dimensions
      11m 11s
    3. Understanding margin collapse
      7m 59s
    4. Calculating em values
      7m 41s
    5. Calculating percentage values
      7m 51s
    6. Normal document flow
      13m 3s
    7. Controlling element display
      8m 53s
    8. Using CSS Resets
      7m 11s
    9. Fixed, fluid, and responsive layouts
      9m 9s
    10. CSS debugging tools
      6m 46s
    11. Using the Firebug Inspector and the WebKit Web Inspector
      11m 5s
  3. 53m 15s
    1. Page design workflow
      3m 6s
    2. Page design tools
      4m 56s
    3. Determining page structure
      7m 18s
    4. Creating image assets
      8m 58s
    5. Creating initial page structure
      7m 3s
    6. Adding meaning with classes and IDs
      5m 23s
    7. Structuring content with HTML5
      6m 6s
    8. Building internal structure
      10m 25s
  4. 1h 36m
    1. Floating elements
      7m 50s
    2. Clearing floats
      7m 28s
    3. Containing floats
      7m 50s
    4. Clearfix technique
      10m 38s
    5. Floating inline elements
      14m 34s
    6. Two-column floated layouts
      8m 17s
    7. Three-column floated layouts
      11m 30s
    8. Column height considerations
      7m 3s
    9. Creating equal-height columns
      10m 42s
    10. Floats: Lab
      5m 25s
    11. Floats: Solution
      5m 21s
  5. 51m 42s
    1. Relative positioning
      7m 59s
    2. Absolute positioning
      8m 59s
    3. Fixed positioning
      4m 23s
    4. Controlling stacking order
      8m 31s
    5. Clipping content
      8m 21s
    6. Controlling content overflow
      5m 38s
    7. Positioning elements: Lab
      3m 59s
    8. Positioning elements: Solution
      3m 52s
  6. 48m 46s
    1. Design considerations for fixed layouts
      3m 28s
    2. Establishing the layout grid
      7m 57s
    3. Defining column spacing
      9m 30s
    4. Applying the grid through CSS
      8m 56s
    5. Creating grid-based assets
      8m 26s
    6. Grid design resources
      6m 22s
    7. Building fixed layouts: Lab
      4m 7s
  7. 44m 35s
    1. Designing for flexible layouts
      2m 30s
    2. Calculating percentage values
      8m 45s
    3. Setting flexible width values
      6m 6s
    4. Making images flexible
      8m 10s
    5. Setting minimum and maximum widths
      7m 24s
    6. Building flexible layouts: Lab
      4m 53s
    7. Building flexible layouts: Solution
      6m 47s
  8. 49m 36s
    1. Responsive layout overview
      3m 49s
    2. Using media queries
      7m 16s
    3. Organizing styles
      8m 39s
    4. Making content responsive
      8m 33s
    5. Mobile design considerations
      7m 32s
    6. Building responsive layouts: Lab
      4m 23s
    7. Building responsive layouts: Solution
      9m 24s
  9. 1h 22m
    1. Creating multi-column text
      6m 36s
    2. Using borders to enhance design
      13m 59s
    3. Rounding corners
      6m 56s
    4. Adding drop shadows
      10m 35s
    5. Working with opacity
      6m 8s
    6. Utilizing the background property
      15m 5s
    7. Working with CSS sprites
      7m 58s
    8. Enhancing page design: Lab
      6m 22s
    9. Enhancing page design: Solution
      8m 38s
  10. 6m 25s
    1. Additional resources
      6m 25s

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

Are you sure you want to delete this note?

No

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.