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

Making content responsive

From: CSS: Page Layouts

Video: Making content responsive

Now that we've discussed media queries and how to properly organize responsive styles, let's turn our attention to some of the ways that we can take advantage of media queries to make our content a little bit more responsive. So I have the content.htm file from the 07_04 folder opened up, and I want to preview the finished version of this for you in the browser first, so I'm going to switch over to my browser here. Okay, so here's our finished page. This is sort of where we're going, and I just want to talk about the different parts of this. Over here on the right-hand side, we have a menu of our archived galleries.

Making content responsive

Now that we've discussed media queries and how to properly organize responsive styles, let's turn our attention to some of the ways that we can take advantage of media queries to make our content a little bit more responsive. So I have the content.htm file from the 07_04 folder opened up, and I want to preview the finished version of this for you in the browser first, so I'm going to switch over to my browser here. Okay, so here's our finished page. This is sort of where we're going, and I just want to talk about the different parts of this. Over here on the right-hand side, we have a menu of our archived galleries.

Beside that we have a branding image. And you'll notice that as I begin to resize this that this layout is flexible. So as I begin to make the page larger or smaller, obviously the different parts of it are responding to that. Now if I hit a specific breakpoint and that breakpoint is for our mobile devices, you'll notice that the layout changes and when the layout changes, the menu stays vertical, but now the branding image is stacked on top of it and it's a much smaller branding image designed more for the tablet-based experience. And if I keep scrolling, you'll notice that this one is flexible as well. And if I go down far enough to hit my breakpoint, here I reach the mobile version of that.

Here we have a totally different branding image and then instead of that long menu that we saw before, because on the mobile screen space is at the premium, we now have a dropdown menu or a little pulldown menu that we can use instead of the actual menu itself. Now page structure doesn't change at all. The only thing that changes here are styles, so let's go into our HTML and CSS and see how we can make this content a little bit more responsive. So here I am, back in the content.htm file, and the first thing I want to do here is sort of scroll down through so you can see the structure of the page, because there are few things here that are a little tricky, and I'm going to go into the HTML to show you what I'm talking about.

In the HTML you can see that once we get down a little bit, we've got a section for our banner so that's that branding graphic that you were seeing, and inside that we have a heading 2 that says Fine urban photography. After that we have our menu and it's just an ordered list with a bunch of links. However, directly after that we have our pulldown menu or our select. So essentially what's happening is at one specific size we're deciding to show one of these elements, and of course that means we're going to be hiding the other element. Now that's not really an ideal way of doing this, because obviously both the menu and the pulldown menu, the select element, still remain in our HTML code, and that means that other user agents or accessibility devices are going to see both of them.

So most of the time when this type of solution is reached, somebody's using JavaScript or some server-side code to inject one of the two of these pieces of code, but for what we're doing right here, we're just going to use CSS. Okay, so I'm going to scroll back up to my styles, and you'll notice that we have some very similar-looking media queries. We're using the exact same ones from our previous lesson. So we have desktop styles, we have our tablet styles, and we have our mobile styles. All right! So the first thing that I'm going to do is I'm going to go down into our tablet styles and our desktop styles. And so I'm going to come right here to the very end of my tablet styles, about line 137.

Now again, always be aware of the fact that that is the closing curly brace of your media query. You don't want to write any styles outside of that. I'm just going to write .menu select, so I'm targeting that pulldown menu inside the menu region. And for my tablet styles I don't want that to display, so I'm going to change the display property to none. I'm going to use the exact same rule of my desktop, so I'm just going to copy that, go down to the very bottom of my desktop styles, again right here, right before the closing curly brace for my desktop styles, and I'm going to paste that and save it.

So that's basically going to turn off the visibility of that pulldown menu for my desktop styles and for my tablet styles. Now for my mobile styles, on the other hand, I do want that to display. So I'm going to go up into my mobile styles--and this is one of the reasons why I love commenting out these regions, because otherwise it would be very difficult for you to know where one region started and another one stopped. So I know the styles right above this are my mobile styles, and here what I'm going to do is I want the menu select to display, but I don't want the unordered list above it to display.

So here I'm going to type in .menu ul to target the unordered list, and I'm going to tell that not to display. I also need to control the visuals of my select, so underneath that, I'm going to do .menu select and I'm going to give that a width of 200 pixels. I'm going to display it as a block-level element, and that's going to allow me to center it using margins. I'm going to do a margin of 1em top and bottom. It's going to give me some space in between my headlines and the menu. And then I'm going to do auto for left and right, which is going to center it.

Now if I save this and if I preview this page, you see we haven't put our image in there yet, but now there is our menu on the desktop version. There is our menu on the tablet version, and you can see the dropdown menu isn't there. And once I go up to the mobile version of that, the unordered list is not showing up, but the Select menu is. Perfect! The only thing we need to do next is take care of our banner image. So I'm going to go back into my styles, and the first thing that I want to do is I'm going to go into my desktop styles. So I'm just going to scroll down into my desktop styles. I'm going to find the banner selector which is right here on line 155, and just below that I'm going to type in a height of 450.

Now this is being driven by the image that I'm using, so I'm making this element the size that my image is. And I am going to give it a background, and I'll just do a URL to point to the image, and I'm going to go _images. It's in the _images directory, and then I am going to do stairs.jpg. And then right after that I'm going to do a no-repeat so that it does not tile. All right! So I'm going to go ahead and save that. And I just need to keep doing this for each one of these. So that was desktop. I am going to scroll up into tablet and I am going to find the banner for tablet, and I'm going to do the exact same thing.

I'm just going to use different values obviously. So for height, for my tablets, that's going to be 150 pixels. And I'm going to do background: url, and then in the url this one is going to be _images/sub.jpg. And once again no-repeat so that doesn't tile. So I'm going to go ahead and save that. And then the last one that we're going to be doing is mobile obviously so I'm going to go up into mobile and I'm going to find banner up in mobile. And I'm going to do pretty much the same thing. I'll give it a height of 200 pixels, and then for background I am going to give a url (_images/glass.jpg) and there again we're going to say, no-repeat.

Now one of the reasons why obviously I chose a background image rather than an image tag, there are a couple of reasons for that. Number one, it's a purely decorative image. But number two, it is a lot easier to swap out background images for media queries than it is an actual image tag. For an image tag we would have to do something very similar to what we were doing with the dropdown menu, which is have multiple images on the page, then hide and show one for one media query, hide and show it another way for another media query. That is really not efficient. You're talking about still having to download all of those background images, and then you have the overhead of turning them on and off.

In this case we're simply requesting the images that we need. So you know, I'm setting here resizing the browser when I test this, but people that use this on different devices, they won't be resizing their browser. If it's viewed on the smartphone, the only image that's going to be requested is glass, if it's viewed on a tablet, the only image that's going to be requested is sub, so forth and so on. So if you're limiting the number of requests it's making to the server, you're making life a little bit easier for the people that are viewing your site because you've lowered the overhead. So I'm going to save that, go back out to my browser, and refresh. There is my image. If you're wondering, the headline is already styled obviously. And then as I scroll down, I get my first breakpoint, and it requests the sub graphic, and as I hit my third breakpoint I now get the glass graphic, and they're all sitting within exactly the same element.

Now even though it's a little bit more complex, it's still a fairly simple example. If you are really focused on making your content more responsive or using responsive layouts, you really have to put a lot of thought into how you're going to structure and style your pages. You know, you have to think not only about what the layout is going to look like, but also about how people are going to be using it, you know things like how content is typically consumed and used on mobile devices versus desktop or how orientation could affect content needs. Now stylistically we can do anything we want now based on a number of different factors, including orientation and screen size. Now my point-- and frankly the main goal of this exercise--is to let you know that you need to start thinking in creative ways about how you can change layout and presentation that is device-specific and focused on how people are likely to use your site.

Show transcript

This video is part of

Image for CSS: Page Layouts
CSS: Page Layouts

71 video lessons · 40902 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
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: Page Layouts.

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 preferencesfrom 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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

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.