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

Mobile design considerations

From: CSS: Page Layouts

Video: Mobile design considerations

While media queries give us the ability to alter our page layouts based on screen size, they can't always control how the page is viewed on devices like smartphones. Now many mobile devices will either misrepresent their screen size or apply an initial zoom to your site that can cause your site to be difficult to read. In this movie I'm going to show you how to ensure that your page displays initially the way you want it to, and a few techniques that you can use to speed up the performance of your site on mobile devices. So I have the mobile.htm from the 07_05 file opened, and I've just opened this up in a browser really quickly because I want to talk a little bit about the meta viewport tag, which is what we're going to be using in part of this lesson.

Mobile design considerations

While media queries give us the ability to alter our page layouts based on screen size, they can't always control how the page is viewed on devices like smartphones. Now many mobile devices will either misrepresent their screen size or apply an initial zoom to your site that can cause your site to be difficult to read. In this movie I'm going to show you how to ensure that your page displays initially the way you want it to, and a few techniques that you can use to speed up the performance of your site on mobile devices. So I have the mobile.htm from the 07_05 file opened, and I've just opened this up in a browser really quickly because I want to talk a little bit about the meta viewport tag, which is what we're going to be using in part of this lesson.

So the meta viewport tag, it gives you the ability to communicate some of your preferences to the different devices that might be accessing your pages, and smartphones almost universally understand this tag. So I've got two things going on in the syntax that you're seeing here. The first thing is the content width= device-width, so that is essentially asking the mobile device to go ahead and set its screen width to what the actual device width is. So essentially a lot of mobile phones, such as the iPhone, will go ahead and display your page as if they had a 980-pixel widescreen. Obviously they don't, so essentially what they are doing is they're zooming out.

So this is something that we call the viewport. So the viewport in a mobile device is usually bigger than the actual screen. So essentially by telling it to set its width to the actual device width, you're ensuring that the entire viewport is going to be visible within the screen. Now the second property that I'm passing into it is the initial-scale=1.0. What that does, it's going to ensure that the device is showing the page at 100% and not zooming out or zooming in on any one portion of it. A lot of mobile devices have a default zoom of about 50%, so that you're seeing more of the page at once.

So this scales it to 100%, so that if you design it for that screen size, then it's going to be viewed exactly the way you want it to. Okay, so with that out of the way, I'm going to go into our HTML. Now you can see that I have several files opened right now. In addition to the mobile.htm file that I have opened, I have four style sheets opened. Those can all be found in the 07_05_CSS folder now. We'll take care of out meta viewport tag first, and then I am going to come back and talk about the style sheets. So after our meta character encoding tag, I'm going to come up and do meta. And then for the name attribute, I'm going to type in viewport. And then after that I'm going to go ahead and pass in content, and for content I'm going to do width = to device-width.

Now I can comma-separate these property, so before I close my quotation mark I'm going to do another comma, and I'm going to type in initial-scale =1.0. So there are a lot of properties that you can pass into that. You can disable user scaling. I mean there are all sorts of stuff that you can do with the meta viewport tag. If you do a quick search on it, you're going to find out all the really cool things that you can do to control how somebody on a mobile device is viewing your file. All right, so I'm going to save that, and the next thing I want to tackle are our style sheets down here. Now this is something that I see pretty commonly when people are using media queries.

They'll create separate style sheets. They may create an overall global style sheet, and then they may separate style sheets for each one of the devices that they're targeting, and then link to them using media queries. Well, this is not a bad approach. The only downside to this, and it is a really big downside, is that you're making several different http requests to the server for each style sheet. And so what happens is for mobile devices, those requests are still made even if they don't need the style sheet. So for a mobile device it would still be making the request for the desktop CSS, even though when it wouldn't be rendering those styles.

Those requests, especially over a slow network, can take a lot of time. So you want to limit the number of HTTP requests you're making when you're designing for that context of responsive design. So what we're going to do is we're going to get rid of all of these except for one request. So I'm going to go ahead and simply request the global.CSS. And again, I can pass any media attribute I want into that. In this case, I'm testing for screen and projection devices. So that's fine. I don't have to change it at all. What I can do, however--I'm going to go into the global.CSS to show you this-- if I scroll down to the bottom of my global.CSS styles, you can see that I have some commented-out style sheets.

I have my mobile files, I have tablets, and I have desktop, and these are using that @media block syntax that we were using in our previous examples. So @media blocks work, even when they're within an external style sheet. They don't have to be just within a style tag in an HTML document. What that means is I can have one style sheet that has not only just the global styles, but also all the groupings of the media queries as well. Now it's going to create a larger style sheet. You're going to have much bigger file, but you're only making one request rather than several requests, and the savings is definitely worth it. So what I'm going to do is I'm going to come in and I'm going to uncomment these out.

So I'm just going to basically comment out each of the titles of these guys. And then after I do that, I'm going to very carefully going to each one of these and I'm going to select all of the text and copy it, so all the styles and copy it, and then come back into the appropriate area and paste them. And I'm going to do that for desktop. Then I'm going to do it for tablet. And I have be very careful. Remember, make sure you're inside the opening and the closing curly braces. And then finally, I'm going to do it for mobile. Now, remember earlier I said I was going to talk to you about how to create cross-browser-compliant word wrapping for your preformatted text, and there is the selector for it right there.

So that's a nice code snippet for you to copy and paste in your files, or if you are ever looking to control word wrapping, that's a really nice snippet of code to have around. It's quite handy. So I'm going to copy these, go into global, roll up to my mobile styles, and then paste them. Now I'm doing one more thing here that I want to point out to you guys, for my mobile styles, that I'm not doing for my tablet or for my desktop styles. For example, this page, if you look at it, we've got this photo gallery and if I resize my browser and hit my target points, the gallery itself changes to sort of fit that format. And when I get into my mobile styles, it becomes much smaller.

Well, it's not just scaling those images. We know that we can scale images, but that's not what it's doing. You'll notice that in the mobile styles, it's actually requesting a smaller version of it. So instead of requesting a much larger image that would take longer to download, by using media queries, I'm able to request a smaller file, which is going to come over faster. It's going to look better, because it's not scaling down. There is no scaling factor involved. And it's a better overall solution for this, and it's only requested if the mobile styles are triggered. So I'm going to save this. Then I'm going to go back to my mobile.htm and save it as well.

You'll notice now that instead of four separate requests for style sheets, we only have one. Now if I save this file and I go back into my browser and I refresh it, I'm not going to notice any difference whatsoever. Everything looks the same, everything reacts the same, and everything is styled the same. The only difference is the amount of requests we're making to the server, and of course we have little bit of control put in place there for our mobile devices. Now if you have an existing hosting account, I encourage you to try out that meta viewport tag, upload it to a live file, and then test that on your phone, and view it in a site that doesn't have the meta viewport tag, and look at the difference between the two of them.

It's a really interesting and powerful way of controlling how your site is displayed. Now there is, of course, a lot more to designing for mobile devices than we were able to cover here. However, the meta viewport tag, combined with media queries, gives you a fair amount of control over how your sites are viewed on mobile devices. And as we were discussing, make sure that you keep file overhead, the HTTP requests, and resource sizes in mind when planning your mobile styles. You know, as designers, we tend to not think about those things very much for desktop, but they are critically important to creating good mobile experiences for your viewers.

Show transcript

This video is part of

Image for CSS: Page Layouts
CSS: Page Layouts

71 video lessons · 40838 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.