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.
I hope you enjoyed working through the responsive-layout lab. Now, creating responsive layouts takes a lot of focus and planning, and just being dropped into the middle of a partial layout like you guys were is a little bit challenging. So let's take a look at the solutions to your tasks and then discuss some of the other responsive features of this particular layout. So I have the index.htm and the main.css opened up from the finished_files directory in the 07_06 folder. And the first thing that you were tasked to do is to create a viewport tag that forces mobile devices to set their viewport width to the actual device width and to set the initial scale at 100%.
And there is the syntax for that right there on line number 6. A couple of things where people typically make mistakes within the syntax is the comma-separated list of properties here. They might have another set of quotation marks, for example. They may forget the comma. So check out your syntax and make sure that it matches mine in that regard. I'm going to switch over to main.css, and let's go down and take a look at our different media queries. So the first media query was mobile devices, the second one was tablet, and the third one was desktop. So I am just going to scroll down and go through all those different media queries.
So the first one I want to talk about is the mobile styles one. You will notice that one is asking for only screen and a max-width of 480 pixels. I don't want these styles to apply to any screen that is wider than 480. Now, the next one was our tablet styles, and for the tablet styles right here on line 517, you will notice that I set a range of values, a min-width of 481 pixels and a maximum of 768. Now, typically where people make errors here, syntax-wise, is they might use the same value here that they used in the mobile one.
So for the mobile they might have had max-width of 481, or here they might have a min-width of 480. You always want those to be different. If they're the same, that means a condition will exist where both style sheets will be applied, and what's going to happen at that point is you are going to have a lot of styling conflicts. You are going to have lot of things reflowing and not looking the way that they are supposed to. So make sure that all of your media queries have unique ranges of values. Now, the final media query--and I am just going to scroll down a little bit further into our desktop styles-- sets to min-width of 769 pixels, again, one more than the tablet media query.
All right! Going back up into our steps, the next thing that I tasked you guys to do was to hide the unordered list in the tablets and mobile styles and then hide the selector in the desktop styles. So I am going to go down and take a look at those in order. So if I go down, all the way down to 965, to my desktop styles--and actually the finished ones are on about Line 970, because of course we have been adding styles-- you can see that I did this a very simple way.
I created a selector that targets any select element inside of a navigation element, and of course we only have one of those in our site, so that was pretty easy to find. And then I wrote display: none. Now, there are a couple of different ways to do that. You could have done visibility: hidden. The reason I used display: none is because it truly removes it from the page, in terms of spacing, so we don't have to worry about any margin or padding that might be native to that select affecting the elements around it. It truly does remove it from the visual display. Now, it's still in the code, so it's not moving it from the document object model, but it is removing it visually from the page.
And I used the same technique on my tablets and on my mobile devices. And if I scroll up into my tablet styles-- and I use the same selection for both of them, so this selector, where I am targeting an unordered list inside of a nav, inside of an aside, so it's a very specific selector, and I'm telling that not to display as well. So I am using another display: none. Now, it's quite possible that you may have written the selector a little bit differently and still achieved the same results. That's fine. It's quite possible that you used a property other than display: none. If that's working for you, that's fine too.
But be sure that whatever selector or properties that you have used aren't causing any odd spacing issues in that region. That's one thing you want to take a look at. All right! I am going to scroll back up to our last step. And our last step was going into the mobile styles and the tablet styles and replacing the larger preview images in the gallery to the smaller preview images. And if I go down to right about line 430, it's going to be in that region. And you'll notice that whereas before they read philly_banner, now the path is sm_philly_banner.
The same is true of the tablet styles. Now, once again, that's going to request the physically smaller file. It's going to fit that part of the layout better. It's also going to be a smaller resource for downloading. So for phones, for tablets, for those types of devices, I am requesting actually smaller images, which is going to help with overhead, which is going to help with performance. Now, I mentioned that those steps obviously weren't the only things that make this layout responsive. There is a lot that went into planning this particular layout.
As a matter of fact, to be honest with you guys, when I started creating this course and some other material, I planned the responsive site first, because if you try to take an existing fixed site or an existing fluid site and change it into a responsive site, you are in for a world of trouble, because there is so much you need to consider. Responsive sites, in my opinion, are best when they are planned from the ground up. All right! I just want to show you just a couple of other regions in the layout that took a lot of planning and tweaking to make responsive. So when you're finished watching this movie, go back into the finished files and then break down the CSS and the HTML that I have used to style those respective areas and you'll get a better feeling for what it takes to sort of plan and strategize out responsive layouts. All right! So I am going to go just into the browser, and I want you to pay attention to a couple of regions.
We are going to start with the menu. You will notice that as I begin to scale down, the menu is responsive, up until a point. There is not a lot of flex there. So when I hit the next break point, we get a little bit more flex within the menu. But notice the difference. The taglines for the menu go away. I don't need to display them at this level, simply because I am running out of screen real estate. The other thing is I have to be cognizant of the fact that for smaller devices such as tablets, and certainly smaller devices such as mobile devices, it's the touch that you need to worry about more than the cursor and the mouse.
So you will notice that the icons in the mobile app are actually larger than they are on the desktop and the tablet. And the reason for that is one of the things that you plan for when you're talking about links or clickable regions within a mobile touch screen is that typically the average size of a human finger that touches is about 44 pixels by 44 pixels. So you want to make sure those linked regions like that are going to be large enough to where people can hit them and touch them without bleeding over into another region, or making them too small to where it's frustrating for people to click.
Now, just below this, I want you to notice the banner area. Here on the mobile device there is no image, so again I'm saving a little bit of overhead there by not downloading an image on the mobile device. The descriptive text and the headline are still there. They are much smaller, and they take up a lot less screen real estate. On the tablet device, you'll notice that the banner image is used, but it's a smaller image. So again, less overhead, fits the space better. The heading is up here towards the navigation instead of down towards the bottom, and then the descriptive text is not overlaying the image anymore.
But on the desktop the descriptive text is over here, mimicking the right-hand column, and then the text is right over the top of it. And then finally, I really want to point out this region right here for you guys, which is the gallery preview region. You will notice on the desktop we have a fairly complex layout. We have the gallery name and the date side by side. We have a large image underneath that, and that large image is responsive in the fact that as you scale, you trim some of it off based upon the fluidity of the layout. And then we have the text underneath it. But as I go down to tablet, watch what happens to that region.
So it dramatically changes. We end up with that smaller gallery preview image that we talked about earlier. Again, it sort of is flexible in the same manner. But look what happens to the headline of the gallery and the date. They change their alignment with the image, and then of course the paragraph text changes as well. And on the smaller devices it goes back to a little bit more vertical layout. But again, instead of being side by side, we now stack these items as well and we use a smaller image. So those requirements for those responsive layouts for those different areas actually caused me to change how I would have normally structured that HTML.
And we talked about this in an earlier movie about how we have an empty sort of non-semantic div tag there for that image, and when I was planning the layout, I really fell in love with this design on the tablet, and it just forced me to say, there's just no other way for me to do this particular layout without throwing in an empty div tag. So that's sort of a concession that I had to make to wanting my layout to be that way. All right! So this lab is over, and you're probably tired of hearing me talk, but there is still plenty for you guys to explore.
Responsive design is a relatively new field, and there's so much more to it than what I can cover here. In fact, lynda.com will soon be adding several responsive-design titles to the Online Training Library, so be sure to keep your eye out for those.
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.