navigate site menu

Start learning with our library of video tutorials taught by experts. Get started

Applied Responsive Design

Applied Responsive Design

with James Williamson

 


Following the concepts introduced in Responsive Design Fundamentals, senior author James Williamson demonstrates the practical applications of responsive design and shows how to enrich the appearance and behavior of your website across multiple devices. First, discover how to plan your design and take advantage of CSS media queries to create multiple layouts. Then make your site navigation respond to changing screen sizes with CSS and jQuery, and display media like images and video fluidly. Plus, discover how to take advantage of mobile capabilities like touch events and HTML5 forms to enhance the experience of mobile visitors. James also shows how to effectively manage resources and optimize the performance of your site.
Topics include:
  • Creating mockups
  • Structuring page regions
  • Defining default styles and media queries
  • Building desktop, tablet, and mobile layouts
  • Structuring and styling menus
  • Dynamically replacing menus
  • Creating a responsive image gallery
  • Adding phone functionality
  • Testing responsive sites

show more

author
James Williamson
subject
Developer, Web, User Experience, Responsive Design, Web Design, Mobile Web
level
Intermediate
duration
5h 58m
released
Mar 07, 2013

Share this course

Ready to join? get started


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:00(music playing)
00:04Hi! I am James Williamson, senior author here at lynda.com, and I want to welcome you
00:09to Applied Responsive Design.
00:11In this course, we're going to explore many of the strategies and techniques
00:14that are being employed to control the appearance and behavior of sites across
00:17multiple screen sizes and devices.
00:20As we explore responsive design, we'll see how it affects the entire process of
00:24building sites, from the early planning stages to site development, and even in
00:29terms of how we test and deploy our sites.
00:31We'll cover the planning aspects of responsive sites, how to craft
00:35responsible layouts and media,
00:37how to handle site navigation across devices and screen sizes, and how you can
00:41use mobile capabilities to enhance your site's overall experience.
00:44We will also talk about properly managing resources for responsive sites and
00:48what you can do to help improve performance.
00:50Responsive design is not just another fad; it's a reaction to the reality of
00:54designing for users who expect to experience your site across multiple
00:58devices and screen sizes.
01:00So, open up your favorite code editor and let's get started crafting
01:04responsive designs.
Collapse this transcript
Using the exercise files
00:00If you're a Premium member of the lynda.com online training library or if you're
00:05watching this tutorial on a disc, you have access to the exercise files use
00:09throughout this title.
00:10Exercise files for this course are arranged by chapter and are located in folders
00:15that are named based on the movie that they represent.
00:18Since each exercise is self- contained, you will want to work with these
00:21folders individually.
00:22I recommend copying the entire Exercise Files directory to the desktop and then
00:27working on the files from the appropriate folder.
00:30I'll call out the location of the exercise files for each movie and you should
00:34see a brief overlay that will also tell you where to find those exercise files.
00:38For this course, I'll be authoring my exercise files using Dreamweaver.
00:42It's a common web authoring tool and in an environment that I am
00:45very comfortable with.
00:46By no means is this Dreamweaver course.
00:49You can use any code editor you'd like, and I cover many of the free and
00:52open-source editors available in several of my other titles.
00:56I'll also only be using the Code view in Dreamweaver and none of its visual tools,
01:00so as long as you can type in the code that you see on my screen, you'll be
01:04able work right alongside with me, whether you are using Dreamweaver or not.
01:08It's also crucial that you use the most recent versions of Internet Explorer,
01:12Chrome, Firefox, Safari, and Opera, and make it a habit of testing your pages
01:17with multiple browsers.
01:18If you have access to a web server, being able to preview your responsive designs
01:22on mobile devices is a pretty critical part of testing responsive design.
01:26During this course, you may want to upload your work to a testing server and
01:30access those pages on tablets and smartphones.
01:34If you don't have access to a live server, I recommend getting a trial
01:37subscription to Adobe's Creative Cloud and checking out Adobe's Edge Inspect.
01:42Edge Inspect allows you to wirelessly sync browsing in Chrome to multiple iOS
01:47and Android devices.
01:48This means that you can update changes in the browser and multiple devices all
01:52at the same time without the use of a web server.
01:55It's a great tool for testing responsive designs.
Collapse this transcript
Exploring the finished project
00:00Before we get started working on our responsive design, I think it would be
00:04helpful to preview some of the things that we're going to be creating over the
00:07course of our exercises.
00:08We'll be working on a few pages of the fictitious desolve.org urban photography site.
00:15As I browse the index page for the first time, I am going to do it all designers
00:20do when they show off a responsive site:
00:22I'm going to resize the browser.
00:24Now you'll note that when the browser window hits the specific size break points,
00:27the layout changes to reflect the smaller screen size.
00:30While this is visually impressive, there is a bit more going on here that I want to point out.
00:35Note that when the page is at that the larger screen size, the layout is fluid
00:40but only up to a point.
00:43When we build our layouts we will construct fluid layouts for each screen size that
00:47is fluid only within a predefined range.
00:50That way we will have layout that will work equally well on any device within a
00:54certain range rather than tailoring our layouts to one specific size.
00:59You'll also notice that the content changes dramatically based on layout.
01:04Taglines resize, reposition themselves, and image is dictated by the context.
01:10In this sense, we will also be exploring how to make sure each design maximizes
01:15the effectiveness of the content within that context.
01:18We'll also be concentrating on how images work within responsive design.
01:23On the index page, you can see that we use a variety of our icons and
01:26background images to enhance our design.
01:29Notice that as screen size changes, icons change and images are either swapped
01:33out, removed, or allowed to flex within the layout.
01:37In our specific gallery page, we'll also add this gallery slideshow
01:42that responds to screen sizes and adds touch capabilities when used on mobile devices.
01:48Navigation is an important part of responsive design, and we will create two
01:53versions of our site navigation.
01:54First, we will explore a simple navigation pattern and the considerations
01:58necessary for maintaining functionality on smaller screens.
02:01Then we will explore this more complex dropdown menu, and we'll talk about some
02:06of the best practices for dealing with limited screen space and ensuring that
02:10it will work properly on touch screens.
02:12We'll also take this related menu and convert it to a selection element for
02:18mobile screens as a way of saving space and improving user experience.
02:22It's also really important to remember when building responsive designs that
02:27your users are, well, really unlikely to resize their screen constantly and
02:31marvel at the changes like we're doing here. They'll simply experience the size
02:35in the context of how it's designed.
02:38As such, we will concentrate on adding mobile enhancements to the site for
02:41smaller screens. We will add phone functionality, take advantage of HTML-
02:46supported form elements, and add home screen icons for mobile phones.
02:52Finally, we will tackle some of the stuff that you can't really see in the demo.
02:55We'll take a look at how we can speed up page loads and how to properly manage
02:58resources for responsive designs.
03:01I think it's also important to note here, as well, that as we start these exercises,
03:05I am going to assume a certain skill level in terms of HTML, CSS, and JavaScript.
03:10If you're a new web designer or just starting out, some of the techniques and
03:13concepts covered here might be unfamiliar to you.
03:16As such, you might want to start out with some of the entry-level HTML, CSS,
03:20and JavaScript courses in the lynda.com online training library before
03:23attempting this one.
03:24We'll also be jumping right in and working with the assets,
03:27so if you would like more background on the concepts and strategies behind
03:30responsive design, check out my Responsive Design Fundamentals course in the
03:34lynda.com online training library.
Collapse this transcript
1. Planning Responsive Designs
Content planning
00:00One of the biggest changes to the design process when designing responsive sites is also one
00:05of the most overlooked.
00:06Everyone tends to focus on the techniques necessary for repurposing content over multiple
00:11devices, while ignoring what this does to the process of actually planning the sites.
00:17In this chapter, I want to take a brief look at some of the considerations necessary for
00:20properly planning responsive designs.
00:23I want to start with the most important component of the entire process, and that is examining the content.
00:29So what you're looking at on my screen right now--I've opened this up in Word--is a content
00:34survey document, and you can find this in the Chapter 1 Exercise Files directory, the 01_01.
00:40I've two versions of this. I have the survey_desolve.doc, which is what you're looking at, and that's
00:45going to serve as our exercise files.
00:47And then I've sort of a blank one that you can use as a template.
00:49If you've never used one of these before and you want to start creating your own, you can
00:53use this as a starting point.
00:54Now, this is a really simple example.
00:56It's not as robust as a lot of the content surveys that I've seen, but what this does
01:01is it's going to help us present the idea of what a content survey is and what type
01:05of things you're going to need to start thinking about once you start planning responsive designs. Okay.
01:09So one of the things that you can see with my content survey here is I have four columns.
01:14I have the content itself; the type of content that it represents; the section of content,
01:20meaning is it site-wide, is it unique to this page, that sort of thing; and then a priority,
01:25meaning how important is this content to the success of this page, how important is it
01:29to the user that wants to take a look at this content?
01:32Now, I've got some footnotes down here at the bottom of this that sort of go over these a little bit more.
01:37So I just want to take just a moment before we get into the example itself, of talking
01:41about what each of these sections is describing.
01:43So in terms of type, there are a couple of ways that you can approach this.
01:47One is to use some existing schemas or taxonomies or microformats that are out there that describe
01:54a certain industry or type of content.
01:56This is especially helpful if you're going to use these types all of microformats later
02:01on to make your content a little bit more accessible or to make more semantically rich
02:07content, because you can sort of already have those in place.
02:09Now, I'm not using anything quite that complex.
02:12I'm basically using sort of a custom content type that allows me to categorize my content
02:17and sort of place it into silos.
02:19Is this part of my branding, is it more informative for the user, is it a type of media, that sort of thing.
02:25Now, the section column to the right of that, this is again a little custom thing that I
02:30use that tells me, what type of content is this?
02:33Is it content that is site-wide, which would be SW?
02:36Is it content that goes in a specific section of my website?
02:40So, for example, if I have a Products section where I have a lot of pages in that that
02:46describe different products, does it go in that section of the website?
02:50Or is it page specific, meaning unique to this page?
02:54Next to that I have a priority level, and of all the things that you do within a content
02:59survey, the listing of all the content on the page, really just going through it is
03:03an important part of the process, because it gives you an idea of exactly how much content
03:08is on that page and whether you need that much content or whether you have gaps in your content.
03:13But probably the second most important part of this process would be the priority level.
03:17How important is this content?
03:19So it allows you to really take a moment to rank the content by level of importance and
03:24develop sort of a hierarchy of the content, and you can start to think about, okay, as
03:29I'm molding a responsive design, what content do I need to keep in the forefront? What considerations
03:35do I need to make for this content when I go down to a smaller screen, and am I making
03:38sure that the highest-priority content is easily accessible to the user?
03:43So this is something that helps clarify and focus a content strategy for designing all
03:49of your responsive designs.
03:50Now, in terms of a priority level, again, I have my own way of doing this.
03:54If I scroll down, you can see I have five levels. I have Critical, Important, Top-level,
03:58Secondary, and Extraneous. Critical is just highly critical content.
04:02It has to be easily accessible to the user regardless of screen size and/or device.
04:07So that's content that I'm always going to try to put to the forefront of the page to
04:10make sure there is not a lot of scrolling or clicking that goes into somebody discovering that content.
04:15The Important level is still a very high degree of importance.
04:19It should be very easily discoverable, probably the first thing that people see if there's
04:23no critical content on the page.
04:25The third level is a Top-level, which is solid page content.
04:29It's important, but it doesn't rise to the level of critical importance.
04:32So it's something you want people to see, you want them to discover easily, but it's
04:35not something that absolutely positively has to be towards the top of the page or immediately visible.
04:40Then I have Secondary Content.
04:41Now, this would be content that's related to the top-level content or secondary content
04:46that I'm just passing along, good information for people to have, but maybe not something
04:50that absolutely positively has to be front and center.
04:52A lot of times this might be ads, this might be sidebar content, that sort of thing.
04:56And then the last category that I have is Extraneous Content.
04:59Now, this is content that once I do a survey of the page and I take a look at it, I really
05:04can't rank it anywhere.
05:04It's content that's like, well, it's kind of nice that it's there, but it doesn't have to be there.
05:08And one of the things that having this type of a priority level will do for you is it
05:12will force you to take a look at content and say, does that content really need to be on the page?
05:17Can I get rid of that content, and if I do, does my page suffer for it or are the users
05:21going to be upset about that content being gone?
05:24Now, I'm definitely not of the mind that for small screens you need less content.
05:28I don't believe that at all.
05:29I believe there are lots of ways to make sure that people on smaller screens are getting the
05:33content that they came for.
05:35So I'm not an advocate of pulling content out of a page just because it's going to go
05:39to a smaller screen.
05:41However, I am an advocate of really taking a look at your content, focusing on it, and
05:46making sure that what you're putting on the page has a reason for being there, because
05:49if it doesn't, then you're just making more work for yourself when you start redesigning
05:53the layout for smaller screens.
05:54So I'm going to go back up to my table here, and I'm just going to run you through the
05:59thought process of going through a survey like this.
06:02So on the left-hand side I have a list of all of the pieces of content that are going
06:05to be on my index page.
06:07This is something that you can do as content is being assembled. You can just start filling this out.
06:11You can do a survey after you've sort of thought about the original structure of the page,
06:15but you want to do this really early on in the process.
06:18This actually could be the very, very beginning of your planning process, is thinking to yourself,
06:22okay, what does need to go on the index page, and just start listing things.
06:26Ranking them can give you an idea of whether it really needs to go on the page or not.
06:29Okay, so the first thing I'm going to take a look at is this section right here for latest galleries.
06:33Now, latest galleries, in terms of types of content, it's going to be a section.
06:36And then I have city name, which is informative, because it's basically telling people what
06:41city they're looking at;
06:42the date, which is informative--when was this gallery uploaded; a teaser image, that's basically
06:48just decorative media.
06:49Now, here is something that's interesting again.
06:51Now, this is my own categorization, so you can come up with what works for your website
06:56or you can use some existing schemas that are out there,
06:58but I actually do differentiate between media and decorative media.
07:01And let me tell you what the difference means to me.
07:03A media would be like either an image or a video that if somebody were viewing this on
07:08a screen reader, or if somebody were just to see the HTML and not any of the styles
07:12applied to it, that that image really needs to be seen.
07:15This is a figure that's like a chart or something like that, something that actually needs to
07:20be part of that content.
07:22Decorative media would be, it's an image that represents the gallery, but it doesn't have to be there.
07:28It's just decorative.
07:30And that allows me a lot of times to think about what's best served by using a background
07:33image and what's best served by using an actual image tag, that sort of thing.
07:37The gallery tagline, that's going to be informative.
07:40Now, I'm going to go down to my site search, down here at the bottom, and social media connect.
07:46I actually list search as being its own type of category. And for social media connection,
07:51that's going to branding, so that might be your, "like us on Facebook," "connect with us
07:55on Twitter," that sort of thing. All right!
07:57So now that I've got all the types of content listed, I can actually start categorizing
08:00that content and grouping them into silos of content and taking a look and saying, okay,
08:04do I have too much in this area, do I have too little here, have I not included a category
08:09that I need? It gives you a nice way of sort of skimming your content without having to
08:12get into the nuts and bolts of it.
08:14Now, in terms of sections, this latest galleries is just going to be unique to the page.
08:19This is a teaser to get people to click into the latest or the most featured galleries,
08:24so all of those guys are going to be unique to this page.
08:26However, the search and the social media connect, that's going to be on every single page, so
08:31that needs to be site-wide.
08:32Now, that allows me to filter the content a little bit more and say, okay, for my entire
08:37site, what content is site-wide, and let's rank that content. And that really helps me
08:40establish my basic page templates.
08:43How should the page layout look? Where should the content be presented that's going to consistent
08:47all the way across the site?
08:49Now I have to go in and think about ranking this. Where does this content fit priority-wise?
08:53Now, I've already got some of the content ranked.
08:55So when I come back in and look at the latest galleries, it's going to be on the homepage.
08:59It's going to let people know which galleries have been uploaded recently.
09:03If they are a frequent visitor to the site, it's going to let them know if there's new galleries
09:07available for them, that sort of thing.
09:08So it's important content, but it's not critical.
09:11It's not going to help them navigate the site.
09:12It's not going to pass along the branding of the company, who is this, that sort of thing.
09:16So in that sense I'm just going to go ahead and rank that with a 2, which means that it's
09:20very important, but it's not critical.
09:22So it's definitely something I want towards the top of the page.
09:24It's definitely something that I want easily accessible, but it's not absolutely critical
09:29that the user be able to see it at first glance.
09:32I'm going to get some strong disagreement from some folks for what I'm about to do
09:35down here for site search and social media connect.
09:38For both of those, I'm going to go ahead and rank them a 3.
09:40Now, that means that they're important, but it means that they're not critical.
09:44It means that they don't absolutely have to be at the top of the page or easily accessible.
09:48Now, I know there is going to be a lot of disagreement with me in terms of the search,
09:52maybe not the social media connect, but in terms of search. Especially for mobile devices,
09:56there's a big trend in deemphasizing navigation and emphasizing the site search over that,
10:01because mobile users a lot of times want to do a search rather than look through a menu.
10:05So you would think that that would rank a little bit higher, but in terms of this site,
10:09in this site alone, this site is very small.
10:11There are only four main sections, and inside each of those sections there might be one or two pages.
10:16So it's very easy for people to discover what they want simply going through a very, very simple menu.
10:22So in my opinion, for this particular site, search isn't quite as important.
10:26Now, if this was a much larger site, with a blog component and a really robust product
10:32section, then I would probably move search a little bit higher up in the priority level.
10:36And that just sort of illustrates that every single site is different and you'll really need
10:40to carefully consider this before you start working on mockups and layouts and wireframes.
10:45Really start thinking about how this content is going to interact with each other.
10:48So this is obviously a really simple example, but this is actually what I do.
10:52It works for the majority of my personal projects.
10:54If I was working on a much larger site, or if you guys are going to be working on sites
10:58run by a content management system or some collaborative process, if you guys are working
11:02on a team together, you're probably going to need to develop a content survey that fits
11:06your site's format and workflow.
11:08Regardless, I cannot stress enough how important it is to start any responsive design by first
11:14examining the content and then developing a strategy for how that content is going to
11:18work across multiple devices.
Collapse this transcript
Creating mockups
00:00There's been a tremendous amount of effort lately to find just the right mockup and prototyping
00:05tool for building responsive designs.
00:06I've seen a lot of people advocating traditional programs that they normally use, like Adobe's
00:11Fireworks, Photoshop, and the program you are seeing here, which is Illustrator.
00:15I've also seen a lot of nontraditional programs like Apple's Keynote and Adobe's InDesign
00:21that allow you to simulate responsive features and functionalities and some animation stuff
00:25being used a lot as well. And there is really a growing number of online tools designed
00:29to allow really rapid prototyping of responsive design sites.
00:33Now, rather than dedicate what would really end up being an entire chapter to demoing
00:38prototyping tools, I really want to discuss how planning response sites requires you to
00:43adopt maybe a slightly different perspective and workflow on the planning a mockup phase.
00:49So I think the best way to show this is just to simply show you my own process.
00:54So I have the file desolve_ mockup opened from the 01_02 folder.
01:00Now, you'll notice this is an Illustrator file, so if you have Illustrator, you could open
01:04this up and follow along with me.
01:05If you don't, you'll also notice that there is a PDF version of the file as well.
01:09So if you don't have Illustrator, feel free to follow along with the PDF if you just want
01:13to get a feel for how the mockup is put together.
01:15Now, before I get started with this, I want to make it really clear that I think the prototyping
01:20and mockup phases of workflows,
01:22I just feel like those are incredibly personal things.
01:24What works for one designer or agency isn't necessarily going to work for another.
01:28You may even use different processes based on which projects that you're working on and
01:32how much interaction you need with the client that you're designing it for.
01:35So now I used to use Photoshop to create all of my mockups, but once I started adopting
01:40more of a responsive design workflow, it really made me rethink how I was creating prototypes
01:46and mockups. For one, I'm not really trying anymore to create pixel-perfect mockups.
01:51I don't find that helpful.
01:52Now, responsive design really forces you to design content that's going to flow and adapt
01:57and change based on factors like screen sizes,
01:59so designing towards one specific size is not only restrictive, but it sets false expectations to your clients.
02:06So I really started the designing for multiple sizes, and that's why I start here in Illustrator,
02:10because one of the things that this allows me to do is you can see here I have multiple
02:14artboards that represent target screen sizes.
02:17So you can see at the top three artboards right here.
02:19I've got one that's going to represent desktops,
02:21I got one that's going to represent tablets, and then I have a mobile artboard as well,
02:25and just below that I have another set.
02:27So I can do as many sets of these as I need.
02:29In this case, I have the top set, which is going to represent the Home page or the index
02:32page, and then I have a second set of artboards that's going to represent a secondary page,
02:37and that's typically how I handle secondary pages.
02:39Now I don't do mockups for every single one of them.
02:42What I'll do is I'll do a mockup for one, so I can get a feel for how that page structure is going to look,
02:46go ahead and start creating templates in HTML for that, and then just design the rest of
02:50them directly within the browser.
02:53And that is a big, big change in my workflow.
02:55So I'm spending more and more time now designing directly within the browser and less time
03:00in programs like Illustrator and Fireworks. All right!
03:03So the first thing that I do is I put down a guide layer.
03:06So I'm just going to start turning some of these layers on individually so you can kind
03:09of see how this works. But I start putting down a guide layer, and this guide layer is
03:12going to help represent how many columns I want, what type of padding I'm looking for,
03:17what type of margins, that sort of thing.
03:19Now, I know there are lot of folks out there that are really fond of grid layout systems
03:24like the 960 Grid layout and some of those other ones, and for more complex layouts I
03:28might actually do something like that where I put eight or twelve columns down using these guides.
03:33But for really basic layouts like this one, I'll usually just stick to two columns, and
03:37you'll notice that both of the artboards are using the same column guides.
03:41So it's really, really simple for me to start putting down the layout.
03:45Now the next thing I do is I have a layer that represents labels, and essentially what
03:50this allows me to do is, kind of outside the outside the artboards, I'll do some labels.
03:54I'll do a color guide.
03:55I'm going to zoom in on these labels so you can see what I'm talking about here.
03:58Essentially, I write little notes to myself.
04:01Okay this is a desktop layout.
04:02I'm targeting 1280.
04:04Now, what I mean by that is I'm not saying this should be viewed at 1280, but I'm just
04:09saying that at 1280 screen size, what is this going to look like?
04:11I mean for all three of these I'm picking sort of an optimal size, with an eye towards
04:16the fact that it still needs to flex within that space. And you can see here I have Max
04:21size 1024-1280, so I'm allowing this layout to flex within that space, and I'm going to
04:26design it accordingly.
04:27That also allows me to come up here and start doing some math.
04:29I'm not very good at it, but it helps me sort of break down what my column layouts are going
04:35to be, if I'm just doing a two-column layout or single-column layout or even an eight- to
04:38twelve-column layout.
04:39I can start breaking down with the math for those who are going to be to achieve the desired
04:43padding and margins and things like that.
04:45I'll also go ahead and put in a color guide if I have one of those.
04:48You can start working from assets that I've got, develop a color guide around that.
04:52I'll put in either the hexadecimal values or the RGB values, or the HSL values, whichever
04:57I'm probably going to be using within my code.
04:58And that way I can just start copying and pasting once I start working in my CSS, so
05:03it's a really neat way of working.
05:04Okay, now the next thing that I do, after I have the labels done and the guides done,
05:09is I go ahead and start blocking out content.
05:12Now, if we go back to what we did in the previous exercise, where we were talking about the
05:15content survey, I really just start blocking areas of content out based on priority and how
05:21much content I have.
05:22Again, I'm going to zoom up on the Home page here, so you can kind of see what I'm doing here.
05:26So I'm blocking an area for logo and branding and thinking how much space it needs to occupy,
05:31how much space I want my navigation to occupy, this visual image for larger screens, that's
05:36sort of a mission statement.
05:38Here's the featured galleries, so how am I going to display each of those, for what my
05:42secondary content is, kind of how that's going to fit.
05:44Now if I zoom out a little bit, you can see that I'm doing this for each one of the layouts,
05:48and I can sort of get a feel for how the content is going to reflow from one screen to the
05:53next, and that's going to help make decisions about structuring the content, about how my
05:57HTML is going to be structured, what kind of styles I'm going to need for that. I mean
06:00I can really start sort of blocking everything out at this point and getting a game plan
06:04for how things are going to fall in. And this allows me to do this really freed up from any visuals.
06:09And you'll notice that I have a little section here for this large visual image that's going
06:13to be on the larger screen and the tablet screens but not on the phone, and that's typically
06:18a visual decision that I'll make. But in this case I'm thinking I really want something
06:23really visually striking on larger screens because this is a website about photography,
06:27so I kind of like to have that.
06:28So even though I'm not concentrating on which image I'm using here, I know that I want some
06:32type of a statement there. And then I can more focus on the content itself.
06:36Okay, now after I go through this stage--and to be quite honest with you, sometimes I do
06:40skip this stage if I know in my head kind of what I'm looking for, but this helps me
06:44really put the content survey that I did in the last exercise into practice.
06:47But after I'm done with this one then I actually start working on the actual design itself,
06:51the content, and you can see I'll turn those content blocks back on and I'm just going
06:55to move them up to the top so you can kind of see how this correlates.
06:58But you can see the content blocks,
07:00they don't really line up all that well.
07:02It's more me just sort of saying, okay, these are the things I want in the order that I want them.
07:07I'm not really working too much with visual and spatial relationships at this point.
07:12I'm just working with where the content is going to go.
07:14Then once I start designing the visuals, I just allow the visuals themselves to determine
07:18exactly where they are going to fit within this.
07:21Now, I know earlier I just said, hey, I don't like doing pixel-perfect layouts, and if you
07:24look at this, it kind of looks like it's pixel perfect, but it's really not.
07:28It's actually quite lazy mockup.
07:30I'm just sort of putting things in place,
07:32some of the elements like the navigation elements.
07:34Now there are some design decisions being made at this point.
07:37If I zoom up, for example, here on the navigation, you can see that I really want some icons.
07:43I've designed these icons.
07:44I want a tagline, so I have the tagline underneath that. And if I go to my tablet mockup, I can
07:50look and see how that menu needs to change. The taglines are going to go away, the relationship
07:55of the icons are going to change.
07:56When I get to the smaller screen, I can see that that's even taken a bit further and the icons are larger.
08:01Now one of the things that I like to point out in terms of this being sort of a lazy
08:05mockup, you'll notice that menu is not centered, and I decided once I got in the browser,
08:10it really looks better centered,
08:11so I went ahead and centered it.
08:12So there are times when you'll do something in your mockup and you'll think to yourself
08:16well, that looks okay, but then you get in the browser and you are like well, that really
08:19needs a little bit of help.
08:20And then you can see here, these are the secondary pages,
08:22again, where I'm just sort of thinking about the photo gallery, what it might need to look
08:26like, playing around with some of the styling options I have for some of the titles, things like that.
08:30So this is really a chance for me to experiment, place the content into the layout, see how
08:35it fits, where everything is fitting, how it looks in relation to each other, and it
08:39really gives me sort of a starting point for what I'm going to be doing within my browser.
08:43Now, another thing that I wanted to point out here, too, is that I do use this for asset generation.
08:47So, those icons that you're seeing there, I am actually using those to export out--
08:52I'll create a sprite files and things like that from those and then export them out for
08:56use within the website.
08:57So that's another thing I really about Illustrator, in terms of designing web graphics, is with
09:01the vector artwork, I can really repurpose the content a lot easier than I can within Photoshop.
09:06Now I still work in Photoshop. I will do certain mockups there, and all of the raster images
09:11you see here are of course generated there.
09:13So there's still that relationship between working in Illustrator and Photoshop, but
09:17I'm pretty much using Illustrator as my go-to mockup program of choice.
09:22Now, that's not the most popular choice.
09:24There are plenty of people out there that are still using Photoshop.
09:26There are people that are using some of the more online tools that they feel give them
09:28a better chance of designing and simulating that responsive flow to the content, and that's fine.
09:34It's just that I know kind of mentally in my head what's going to happen with the content.
09:37I can even make notes to myself, and this allows me to really design it in a way that I'm visually comfortable with.
09:44Now, I do want to point out that along with all these steps that I've sort of outlined to you,
09:48I also, usually in parallel, will design how the user experiences is going to change based on screen size.
09:54To give you an example--let me zoom up on that so you guys can see that a little bit better--
09:58here we have this Archive galleries menu on the large screen, but you'll notice that once
10:02we get to the small screens I'm representing that with a dropdown menu.
10:04So I'm thinking about user experience at this point too. What's going to be better for people
10:08on small screens? How is that going to work?
10:10The user experience side of it deserves a longer discussion, so I'm going to tackle
10:13that in our next exercise.
10:15But before we move on to that, I do want to reinforce the fact that this is simply my workflow.
10:20It might work for you and it might not.
10:22My advice is to take from it what you find useful and then go ahead and adopt that for your own purposes.
10:28I'll also be adding some additional prototyping and wireframing tools for you to look at in
10:32my "Additional resource" movie at the end of the course, so be sure to look out for that as well.
10:37
Collapse this transcript
Planning responsive UX
00:00Planning a responsive website is more than just designing for mobile screen sizes.
00:04Now, you are going to have to think about how visitors will use the site and what their
00:08expectations are across multiple screen sizes and devices.
00:12In this exercise, I am going to return to the mockup that we were just looking at and talk
00:16about my process for exploring the user experience across multiple devices.
00:20So, again, I'm working in desolve_mockup.ai, but this time I am working on the one that
00:26can be found in the 01_03 folder.
00:29There is also a PDF version of it in there as well, but you won't be able to do some
00:33of things that we're going to working with.
00:35So, as I mentioned in the previous exercise, a lot of the step that you are going to see
00:39me doing here I'll do in parallel as I'm designing it.
00:42I don't do this in a two-step process. As I'm working on the visual aspect of the design,
00:47I'll often leave callouts or notes to myself, or put some symbols on the page that sort
00:51of explore the functionality of how something should behave or how people can interact with it.
00:56So, I have got a layer at the very top of my layers called UX callouts.
00:59I am just going to turn that on.
01:01Now I have got some existing ones in place. Just to give you an idea of what these do,
01:05I am going to zoom up on a couple this here.
01:08And this is on the tablet version of the homepage. And you can see I just have a little callout
01:11here that says, "Use a smaller version as background graphic."
01:14So, rather than making somebody on the smaller screen downloads the big version of it, create
01:18a second version of it that is smaller.
01:20For example, here I'm wanting to reposition the copy next to the image is going to require
01:24careful thought about the structure of these element.
01:26When I am designing something--I visually say, well, it fits better like this, but then
01:30when I compare these, I am thinking, okay, how am I going to structure that HTML, how
01:34is this CSS going to be written?
01:36So, writing a note to myself there to let myself know, hey, this is going to require
01:39a little extra effort on your part. And I have got just a couple of callouts.
01:44Now, I'm not always just doing callouts. Sometimes I am simulating interactivity or a widget,
01:49like an accordion widget, or tabs and things like that.
01:51I don't really have any of those on the homepage, so I don't really have anything to show you there.
01:56But I am going to scroll down to the second set of pages down here, and we're going to
02:02add some callouts on our own here. And I am just going to show you how I might talk about
02:07how an application or an interactive element should behave and that what its behavior is going to be like.
02:13All right, now the first thing that you'll probably notice is that there are some weird
02:16text going on here for Philadelphia, but not here on the mobile one.
02:21And I would like to do something kind of fun with the text for each city gallery. So for
02:26Philadelphia, you know seeing at its history, I have got an off-blue, and a red, and a white
02:32version of the text, and I am sort of offsetting them.
02:34I'll probably do something a little bit differently in the browser. As a matter of fact, I will
02:37spare you the suspense and tell you I will do something a little different in the browser.
02:41But this is the general idea.
02:42So, what I am going to doing is I am going to go over to my symbol libraries, and I have
02:46a custom symbol library that I've created called Touch, and I highly recommend that you
02:51spend some time, if Illustrator is your tool of choice or Fireworks is your tool of choice--
02:56it has symbol libraries as well--
02:58going and creating a separate symbol library that has all of the callout symbols and interactive
03:03elements in it that you might find yourself using from time to time. It just makes life so
03:07much easier when you go start placing these things on the page. You don't have to worry about
03:10copying and pasting from other documents; they are just in a symbol library. Okay.
03:13So, here I am just going to grab this callout and drag it to the page. And I want to make
03:19sure I am dragging that to my UX callout layer,
03:21so let me go ahead and lock all these other layers down.
03:23I have a bad habit of doing that. As soon as you select something on a page, it goes right to that layer.
03:29Okay. Now because this is a symbol, if I went ahead and edited this, it would change it everywhere.
03:34I don't need to do that, so I am going to get rid of my Symbols palette and I am
03:36going to decouple that. And right here I am just going to mention, I'll just type in the
03:41text a little note to myself.
03:42I am just going to say the "Lettering effect will be for large and tablet size screens
03:53only." And that might effect the scripting that I do for that lettering effect.
03:59It might have to change the styling that I do for it.
04:01It might change how I load external resources if I need anything to affect that. It's just giving
04:06myself a little heads-up within the mockup that when I start planning how the site is
04:10going to be structured and coded that that is definitely something that I need to keep in mind.
04:14Now, just below that, I have an art gallery and you're going to notice that this gallery,
04:18you know, it's not big--you can see it's only got six images in it.
04:21So, what I would like to do here is do some type of modal window so that if somebody
04:25clicked on one of these images, they could get a larger, maybe even a full-screen version of it
04:29that they could take a closer look at.
04:30So, what I am going to do is I'll go back to Touch library, and I am just going to drag
04:34a symbol for a modal window to the stage. And then I am just going to increase the size
04:40of that. And you can even do things like transparency. If you really wanted to keep seeing underneath
04:45it, you could take the Transparency to, say, 90% or something.
04:48It's totally up to how you would want to do that.
04:51And then I'll put another callout to the right of that. And then again, I am just going to
04:55decouple that symbol so I can write in without editing the other ones.
04:59And I'll just go in, and in this one I am just going to say something like, "The gallery should
05:05be smaller images than launch modal window."
05:12So, I'm thinking through the behavior, kind of how I want this to react, how I want this
05:17to be scripted and put together, that sort of thing. And then for the smaller screens,
05:21it has its own unique considerations.
05:23So, I'll take another modal window to the screen, and because it's going to affect both
05:28of these, I am just going to make sure that it's over both screens. And this is just sort
05:32of a way for me to say, hey, this is going to apply to both of these.
05:36And then I'll take another callout. And I might even size that up just to tad bit, break its
05:45link too. And then inside of that, I would want to come in and say, "For smaller screens
05:51modal gallery should support swipe events."
05:59And the reason I say that is because most of the users, once they open up a photo gallery
06:04in sort of like a full-screen window like that, what they expect is to be able to swipe back and forth.
06:09Now, I also like visually indicating that, so I have a little symbol that indicates swipe,
06:14and I am just going to place that on the page and increase that.
06:17Now, if you are wondering about these touch symbols, I did not create these. Towards the
06:21end of the course, in the "Additional resources,"
06:24I am going to show you guys where you can go find some really nice open-source and free
06:28symbol libraries for touch events and things like that.
06:30And this is one of those that I pulled from one of those galleries. And in my touch thing,
06:33I have just got a ton of these, indicating touch and holds, double taps, pinches, and zooms.
06:38That's really important when you're doing responsive designs, because a lot of times
06:41you're going to have to indicate that type of functionality, and having a symbol that
06:45allows you do that means that when you look at a mockup or if a team member looks through
06:49your mockups, they can very quickly see kind of what you have in mind:
06:52"Oh, this is going to open up a gallery window, and you want people to be able to swipe through the images, okay."
06:57Now, how detailed you get with this particular stage of doing these types of responsive UX
07:02callouts and symbols is really, it's just up to you. Or it might even be driven by the
07:07amount of collaboration that you are doing with either your colleagues or clients.
07:10Now, I encourage you to come up with graphics and symbol standards that are going to add
07:15consistent meaning to your wireframes and mockups, and those will help you work through
07:19the very tricky problem of addressing user experience across multiple devices.
Collapse this transcript
Structuring page regions
00:00Once you've planned your page content and worked through the initial design, it's time
00:04to turn your attention to your site's initial page structure.
00:07Now, I always do the exact same workflow. I'll start with the basic page container elements,
00:14and then I begin to structure the content inside of them.
00:17Now, this allows me to focus on the semantics of the code and ensure that it's going to
00:20work the way that I expect it to across multiple devices.
00:24So you might be wondering, if I'm talking about structure and code, why in the world
00:27am I still in Illustrator?
00:28Well, I want to show you guys sort of how I plan the structure and code, and then we'll actually
00:33go and structure it.
00:34So here I am in the dissolve_mockup, found in the 01_04 folder, and I've got another
00:40layer over here now called page structure. And I'm just going to turn this on, just kind
00:43of show you how I do this.
00:45What I'll do is I just is use solid shapes to represent containing elements.
00:49And I really look at the content on the page and start thinking about how that content
00:52needs to be, or should be structured.
00:54For example, you'll notice in the site, the header here and the nav are separate elements.
00:59I certainly could have placed the nav inside the header,
01:02but in terms of how I'm going to repurpose this navigation, I thought that it would be
01:06a lot easier and a lot cleaner to keep the header and the nav separate from each other.
01:10I then start thinking about how these elements all relate to each other.
01:14And in terms of the article, which is going to be the main content; and the aside, which
01:18is secondary content; and this mission statement up here, which is you know really just a sort of a banner,
01:24those all three almost relate to each other so it makes sense to contain them inside of
01:28another element. In this case I'm going to use a section.
01:31So I'm also taking a look at the different elements that I'll be using when I structure
01:35my page as well. And at the very bottom of course I've got a page footer.
01:38So when I'm looking at this, I'm really thinking about, what's the simpler structure I can use
01:42and still get the layout that I need and still have the flexibility that I want.
01:46That's one of the things that you really, really need to plan very carefully at this
01:49stage, while you're still doing your wireframing and your mockups, because we're still at the
01:54point where source order matters.
01:56We can't really use, with any measure of confidence, to grid layout system in CSS or Flexbox yet,
02:02so we're really you know stuck with still doing float-based layouts and if we do that,
02:06then source order matters.
02:07So, depending about how I want content to reflow from one screen size to the next or one device
02:12to the next, I really need to start thinking about that source order.
02:15So once I've mapped this out, I can then start coding it, and I'm going to switch over to
02:19my code editor, which is Dreamweaver.
02:22And here I have the undex.htm file open from the 01_04 directory.
02:27Now, I told you guys you do not need to use Dreamweaver, and that is absolutely true.
02:32If you are using Dreamweaver and you're wondering, how do you get it to where it's just showing
02:36the files you are working on?
02:38Essentially, I have defined one site and then every single time I work on an exercise I
02:43redefine local root site to the exercise folder, so that's really all I'm doing as far as managing it.
02:49Okay, and you're not using Dreamweaver of course that doesn't mean anything to you and you don't care.
02:53All right, so the first thing I am going to do is go into the body, and I'm just going
02:56to think back to the page structure that I had sort of determined through my mockup,
03:00and the very first thing was the header.
03:02So I'm going to go ahead and create a header element, so I'm using HTML5 elements.
03:05I'm going to go ahead and give it an id, and that id is going to be pageHeader.
03:10Now this is a personal choice.
03:11I know a lot of people have gotten away from using ids.
03:13I still use them because they're unique identifiers, especially for the top-level page element,
03:17so I really like using them.
03:19The next thing I going to do is use a role, and the role I'm going to use here is banner.
03:23And those roles help with accessibility.
03:25It helps the content to be a little bit more semantic and it's going to help with accessibility
03:29in the long run as well. And since I'm done with that, I'll close the header tag.
03:32Next, I want a nav element for my page navigation.
03:35I'm going to go ahead and give that an id of mainNav, and then I'm going to give it a role of navigation
03:42as well. So we're setting those roles as well for each of these.
03:48And the next thing I'm going to do is do a section and remember, the section is going
03:51to be my main content, so I'm going to give an id of content and I'm going to give that
03:55a role of main. Currently, I've read there is a lot of talk in HTML in terms of adding
04:01the main element itself in addition to section and article, and I'm a huge fan of that;
04:06I hope that happens.
04:07The next thing I'm going to do is I'm going to use a div tag.
04:10Now, you'll notice that for most of what I'm doing here--and this one is going to have
04:13a class of mission because it's going to be the mission statement.
04:16You'll notice that most of what I'm doing here are HTML5 semantic elements,
04:21but one of the things that I really try to do is to create a really clean document outline
04:26so that if there is any type of a reader or any type of feed out there, like the Google
04:31TOC that it gives you, that sort of thing,
04:33I want it to be really clean and readable. And the mission isn't really a section in content.
04:38It doesn't really fall to that level of importance, so in that terms, I'm using a div tag for that
04:42instead of one that are more semantic sectioning elements.
04:45Okay, right after that, I'm going to go ahead and do an article. And this article is going
04:50to have the id of latest.
04:52This is my latest galleries. And then just after that is an aside.
04:58And the aside isn't going to have an id because its just related to the article content, but
05:03I'm going to give it a role, and that role is going to be complementary. So I don't give
05:07everything ids. And you'll notice also that the div, the article, and the aside are all
05:13still within that section.
05:15Now, breaking outside of that section, I'm going to go down and do my footer.
05:21And the footer is going to have an id of pageFooter,
05:23sort of a top-level containing element, and its role is going to be contentinfo.
05:29I'll go ahead and close the tag and then save it.
05:34One thing that I want to point out you guys is if you've watched any of my other titles,
05:37I really stress creating very clean, very semantically proper HTML.
05:42I stress that all most to the point of, I'm sure, from time to time people go, okay, yeah,
05:47we get it, well-structured HTML.
05:49But the thing that I really like to point out in terms of responsive design is that
05:53later on we're going to be using media quires to filter which styles are going to be applied,
05:56later on we're going to be running some jQuery that's going to apply different functionality
06:00based on screen size and devices and thing like that.
06:03But when it all boils down to it, if any of that fails, you're only left with your HTML.
06:08So if you think about what the first absence of the media query or the absence of JavaScript,
06:12but the first thing, the first responsive design that you are making is this one: it's your code.
06:18So source order matters, how well it is structured matters, because this code can flow almost anywhere--
06:24anyplace that it can read HTML. So when you think about responsive design, the HTML portion
06:28of it is often really dramatically overlooked.
06:30It's a very important part of creating that responsive content that flows from one device to another.
06:35All right, so just remember, careful planning of the page structure, especially these main
06:40content regions that we were just working on will, really help prevent problems later
06:44on down the road.
Collapse this transcript
Structuring content for multiple devices
00:00One of the things that responsive design really does is it forces you to carefully consider
00:06just how your content regions should be structured.
00:09Our existing requirements on float-based layouts means that source order and the element structure
00:15will directly affect how you're going to be able to repurpose content across multiple
00:19screens and devices.
00:20So, I want to take a look at how would you go about planning your designs and how that
00:25can directly affect how you are going to be structuring your content.
00:28Now, I've got the mockup opened again, but we're not really going to be doing anything
00:32with the mockup per se, so don't feel like you have to open this one up as well; you
00:35can just kind of check out what I am doing here.
00:36I want to draw your attention to two areas: one in the larger desktop version, and that
00:42is the featured gallery section over here with Philadelphia and the photo and the Join
00:46us as we visit the city of brotherly love, and then the same area over here on tablet
00:52devices, or the tablet layout if you will.
00:54Now, you look at it and you could tell it's using the same content, and you can see that
00:59the structure of that content anyway is being more or less repeated underneath it.
01:02We've got a gallery for Chicago, gallery for New York, and they're really following the same
01:06structure each time out.
01:07So, that's a clue right there to me that obviously I am going to be using some type of containing
01:12element for each one of these galleries.
01:13It could be a section, it could be an article, it could be a div tag, whatever I really wanted to use for that.
01:19But when I start thinking about the interior structure of that, then I'm presented with some issues.
01:25Now, the first thing I need to think about is this teaser image being displayed for both
01:29of these galleries.
01:31It looks like the same image, but it's really not.
01:34It's a smaller version of it, and for responsive design, it's actually better if I can use
01:39the smaller images for tablets because it's less resources, or smaller resources anyway,
01:43smaller file sizes to download.
01:45So, that's something I need to consider.
01:47The other thing I want to consider: Is this going to be an actual image or is it decorative?
01:53And when I look at this and I think about how a screen reader might read that, or if
01:57somebody is just getting the information from the site, do they really need to see that photo?
02:01And the answer is probably no.
02:03So, that tells me that this is a decorative image--or at least I made that decision that
02:07this is going to be a decorative image.
02:09That means it is going to be the background image for an element.
02:12And then I started thinking about the rest of the structure. We have the name of city--Philadelphia
02:16in this case, so that's going to be a heading.
02:18Then we have a date, which indicates the date that this is published, so I'll need to indicate that that's a publish date.
02:23That's another element.
02:24And then we have sort of a tagline or a teaser line if you will, "Join us as we visit the
02:29city of brotherly love," so that's a third element that's in place.
02:31So, I need to think about how all of those elements are going to be dealt with, and I
02:34need to think about how that image is going to be displayed.
02:37Now, because this is all going to be wrapped in a parent container, a section, or a div tag,
02:42or something like that, I could certainly make that image a background graphic for that
02:46and then just use sort of padding and positioning of the background image to get it where I
02:51need, so I can kind of do it that way.
02:53But I also have to consider user experience.
02:55If you're going to launch this gallery, are you likely to only click the word Philadelphia,
03:00or you are likely to try to click that image?
03:02I guarantee you that most people are going to want to click or touch that image to open up the gallery.
03:07So, it needs to be clickable as well.
03:08So, if I did the entire background then I would need to use a block level link, and
03:13that leads to some problems in certain browsers. I try to stay away from them if I don't need to use them.
03:18So, I might think of another way to do that.
03:21We're about to go and structure this. And the reason that I spent so much time looking
03:25at the mockup and talking through my thought process is I want to give you some idea of
03:30some of the things that you'll need to start thinking about when you go from, say, desktop
03:35to tablet to mobile, and how that's going to affect the structure of your code, how
03:40that's going to affect when you decide whether an image is going to go in or whether it
03:43be a background graphic, what the consistency of the code is going to be like, because in
03:48both the mobile and the desktop version, really those elements are sort of stacked one on top of each other.
03:53The heading and the date are floated over here, but other than that, they're kind of
03:56stacked on top. Whereas here, we can see that the image is actually floated to the right
04:01of the text, and that creates a really unique structural problem, for us in terms of how,
04:06do we do that in a way that's going to allow us to float everything or position everything
04:11the way we want it to in both layouts. Okay.
04:14So, I am going to switch over to the index.htm file, which is found in the 01_05 directory.
04:21And we're just going to structure that one section.
04:23You'll notice that there's quite a bit more to the page here than we left it in our last
04:27exercise, and that's because I've pretty much structured everything on the page except for those galleries.
04:33So I am going to continue to kind of scroll down until I find this article here that it
04:38has a headline in it that says, "Our latest galleries."
04:40So this is where our featured galleries are going to go,
04:42so right underneath that heading, I am going to create a blank line. And I mentioned that
04:46we're going to need the containing element for each one of the featured galleries, and
04:50we could use a section or we could use an article. Since I don't see them standing alone
04:54on their own elsewhere, I tend to use a section for those.
04:57So, I am going to do a section, and I am going to give it a class of philly, since the Philadelphia
05:02Gallery. And then I'll go ahead and close that section.
05:06So, this is the containing element that's going to wrap around--each one of those
05:10featured galleries will have its own section.
05:12After that, I am going to do a heading, and so I am going to do an h2.
05:16Since I've already used an h1 in the article itself, I will use an h2 to be the main heading
05:21within the sections. That gives it sort of a hierarchy, in terms of the importance of it anyway.
05:25I am just going to type in Philadelphia and close the h2.
05:31Now, I do want that to be a link.
05:33I do want people to be able to click on the heading and jump to the gallery itself,
05:36so I am going to take the word Philadelphia and then we'll wrap that in a link tag.
05:40I am going to give it an href attribute of philadelphia.htm.
05:43That's where we're going obviously, and I'll give it a title of the Philadelphia gallery.
05:51So, after that h2, I need to think about what comes next, and if I go back to my mockup,
05:58you take a look over at the mobile, after the headline we have our date.
06:01If we look at the tablet, after the headline Philadelphia, we have our date, all of the
06:05images over there on the right-hand side, and in the desktop version of it right after
06:10the heading, if you go to the right, there is the date,
06:12so the date is a logical choice to be next.
06:15So what I am going to do is after the h2, I am going to go ahead and create a paragraph.
06:18I am going to go ahead and give it a class of pubdate, for publication date. And then
06:24inside that, I am just going to do August 2011. Close my paragraph.
06:30Now, I want to make this information as semantic as possible, and this actually is a publication date,
06:37so it would be really nice if any type of robots or machines that are scanning through
06:41this document is able to pull these publication dates out of here.
06:44So, what I am going to do is I am going to wrap this in a new HTML5 element called the time
06:48element, and there has been a lot of controversy surrounding time. It was pulled out.
06:52It was changed, reformatted.
06:53It's back now, and everything seems to be okay.
06:55So I am going to use the time element, and I am going give it an attribute of datetime.
06:59And the datetime, I am going to pass into that 2011-08-16.
07:07And that's just a simple year-month date format, and I will close that.
07:12So it just wraps around that text. You won't see it.
07:14It doesn't affect rendering, but it does make it a little bit more machine-readable, a little bit more semantic.
07:19And then finally, at least in terms of the initial structure here, I am going to do another
07:22paragraph, and inside that paragraph I'll give that a class of caption, because it's
07:26going to be the caption for the gallery.
07:29And inside of that paragraph, I am going to type in, "Join us as we visit the city of brotherly love."
07:37In terms of information and semantics, that's all we really need for this, but there's one
07:41big elephant in the room and that would be the image itself.
07:44Now, I mentioned earlier that we could take one of these elements, like the heading or
07:48the section, and make the image a background graphic of that,
07:52but we have that problem of, in the layout, wanting to not only stack a content on top
07:57of it and below it, but also beside it based upon which screen size we're looking at it
08:02on, and that's going to cause us to really think about how we're going to structure this.
08:06And if I look again over at my mockup, it seems that if you're going to really rank
08:11them in the order that they appear, we have heading, publication date, image.
08:16If I look over here at mobile, we have heading, publication date, image.
08:20If I look over here, this is a little different; we have heading, we have publication date,
08:26we kind of have an image, and then we have that.
08:28But you could also make the case that this one is going more a heading, publication date, caption, and image.
08:33But it really just depends on how we're going to structure this, but it seems to me that
08:37at least--at the very least--the heading and the publication date need to come before the image.
08:41So, what I am going to do is, right after the publication date, I am going to go ahead and create a div.
08:47Now, I know this is nonsemantic. I'm placing in an element that doesn't really need to be
08:52there, but occasionally for design, especially one like this that's really going to change
08:56based upon the screen size, you may have to do that.
08:59So sometimes you have to make the decision to place in a nonsemantic element.
09:02So in this case, I am going to do a div.
09:04I am going to go ahead and give it class of Preview, because it's the preview image for
09:07that gallery. And then inside that, I'm going to place a link, because remember, we want
09:11this image to be clickable. So I am going to give it an href of philadelphia.htm, so
09:18the exact same link that we were using before.
09:21I will go ahead and give that a title of Philadelphia gallery.
09:26So we're just mirroring what we did just above that.
09:30And then, we'll close the link, and we'll close the div.
09:33So it's not going to have any actual content.
09:35It's just going to have the link and a div tag, and then through CSS, we'll place the
09:38background image inside of that and then define the dimensions of the link in the clickable area.
09:43And we'll be able to do that for each of our layouts: for the desktop, for the tablet, and
09:46for the mobile layout.
09:48So, I will go ahead and save that.
09:49Now, of course the Philadelphia gallery wasn't the only one, so I would advise you to go
09:54ahead and open up the finished_files folder inside the 01_05 directory, open up the index there.
10:00And if you scroll down, you'll find not only the philly gallery that we just structured,
10:03but also the one for the Chicago, New York City galleries as well.
10:07So take a look at those, kind of see how the structure mirrors itself and repeats itself.
10:11And feel free at this point to pause the video and go ahead and structure those yourself
10:15or copy and paste the code, get a really good feel for exactly how each of these featured
10:19galleries is going to be structured.
10:21Now, just because I did it that way doesn't mean that that is the choices that you would have made
10:25if you were looking at the same mockup and structuring it as well. I mean, any project
10:28you work on, how you choose to structure the code is largely a result of your own personal
10:32preferences within whatever commitment you have to standards and semantics.
10:36However, when you're building a responsive site, one of the things that I really want
10:40to emphasize to you is that you're often going to need to take into consideration how the
10:45content reacts to changing screen sizes, and that's going to help you make the final determination
10:50of how elements should be structured within the page.
Collapse this transcript
2. Building Responsive Layouts
Controlling the viewport
00:00In this chapter we are going to explore the basics of creating responsive layouts.
00:04Making sure that you have a solid layout across multiple screen sizes is one of the core foundational
00:09aspects of any responsive site.
00:12Before we get too deep into the techniques involved with creating multiple layouts, we
00:16first need to explore how to control the viewport on mobile devices.
00:20Now, mobile devices have a default viewport size that determines how websites are displayed
00:25within their browsers.
00:26For the most part, this default viewport is set to actually a much higher value than the
00:32actual screen size. This allows users to see the entire site, although at a dramatically scaled-down size
00:38so then they can zoom and pinch and move around where they want to go.
00:41Now by controlling the viewport, we can also override those defaults and make sure that
00:47the site is being displayed at the size that we want.
00:49So in order to do this, I am going to open up the index.htm file in the 02_01 folder
00:56found in the Chapter2 folder within the exercise files. And this is extremely simple to do. Very, very easy.
01:02So, just right up here at the very top, after the title and before the link to my external
01:07style sheet, I am just going to create a new tag here, and we are going to use a meta tag
01:12with a name of viewport.
01:13And this is sometimes referred to as the meta viewport tag.
01:17So, it's meta name="viewport." Now, this is the most common way of dealing with controlling the viewport.
01:23There is a new CSS rule called @viewport that is gaining support across devices,
01:29so eventually, if we want to do this inline within our CSS, we can. But right now the
01:34primary way of controlling the viewport across devices is to use the meta viewport tag. Okay.
01:40Now, the next thing that we need to do is we need to give it a content attribute.
01:44And it's in the content attribute where we really the most of the work here.
01:49Now, we are going to use width, so I am going to give it a width=.
01:53Now here, you can pass along a specific size if you wanted to.
01:56So, if you are designing an application, for example, so that it was exactly the size that
02:01you wanted to, at 380 pixels, then you could make the width=380 pixels.
02:06That's not really going to work for us in terms of responsive designs, because we really
02:10want our design to be able to flex.
02:12All we really want is we want the mobile browser to not display its viewport at, say 980 pixels,
02:18which causes the whole thing to get sort shrunk down within the available 320 to 400 pixels
02:24that to your mobile phone might have.
02:26So here, I am going to give use a value of instead of a specific pixel value,
02:32I am going to tell the width to be equal to the device width, and that's device-width.
02:38Now, what that does for me is it goes ahead and says okay, to the devices, it says okay.
02:43What is your actual screen width?
02:45Not what you're reporting your viewport at, what is your actual screen width?
02:48Oh, you only have 320 pixels? Okay, fine. Then that's what the viewport is.
02:52So, it syncs up the width of that sort of imaginary viewport to the actual size of the screen.
02:57Now, if you're having trouble visualizing the viewport being different than the actual
03:02screen size, just open up your browser in your laptop or whatever computer you're using
03:06right now and then go resize the browser window.
03:09That's the viewport.
03:10So, on the desktop, we are typically making that viewport smaller than their actual screen
03:15size, but on the mobile devices, they take that viewport and make it bigger.
03:19They actually make the viewport a little bit larger, and then they sort of shrink it down
03:22within the screen width. All right!
03:24So, by saying width=device width, we are forcing the viewport and the screen size itself to
03:29be in sync with each other. Now you can take this a little bit further too.
03:32I can use a comma-separated list of values here for content.
03:35So, after width=device-width, I can also say something like initial-scale=1.0. And this
03:43is actually very common; you'll see this a lot when you see the meta viewport tag.
03:47Essentially what this does is it says okay, make the initial scale at 100%, because a
03:51lot of times when the viewport is much larger than the screen width, they use scaling factor
03:56to shrink it down so that it does fit within the viewport
03:59so you can still see the entire site, even though it is zoomed way out. And this takes
04:03care of that as well.
04:04Now there is one thing that I to want to mention here.
04:06If you force the viewport to be the same width as the device-width, then initial-scale factor
04:11is already taken care of.
04:13So a lot of people are dropping that initial-scale declaration and they're just saying content-width=device-width,
04:17because it's really kind of overkill. But it's not hurting anything to leave it in, so feel
04:23free to go ahead and leave that in. That's fine.
04:26Now all I've to here is remember to close my tag; that's kind of important. And then I'll save this.
04:32Now, it is extremely easy to overlook adding a meta viewport tag to your responsive designs,
04:38but it's a really important part of any responsive design project that you work on.
04:43Now, without it, you are going to find that all of your carefully crafted mobile and tablet
04:48layouts simply just don't look or perform the way that you'd expect them to.
04:52So, just like we did here, make sure that adding them is the very first step in building
04:57any responsive layout.
Collapse this transcript
Defining default styles
00:00If you sneaked a peek at the finished project, you may have noticed that the final CSS file
00:05has over 1500 lines of code in it.
00:08I know that sounds like a lot, but once you realize that that's actually three separate
00:13layouts, as well as all the site's global styles, it's really not that bad.
00:17It is not even minified; so yeah, it's not too bad.
00:20Still, what that means is we are not really going to be able to write every single style
00:25or line of code in this course.
00:26It would just simply take too long.
00:28So instead, I want to focus on the theory and the approach that I use when building
00:33a responsive layout.
00:34Now that means that we are going to be constructing specific parts of the layout while focusing
00:39on the overall concept.
00:41Now, the first concept I want to cover is the idea of identifying and writing global styles.
00:46I am going to switch back over to our mockup here for just a second.
00:50Now, how you do this is going to largely depend on your own individual workflow, but the basic
00:55concept of it goes like this.
00:57Before I start working on individual layouts for different screen sizes, I first identify
01:03common styling requirements for each of the layouts and then I'll write those styles
01:07in a way that allows me to apply them to all layouts.
01:11So here, looking at the mockup, I can start looking and saying, okay, well, obviously
01:16this sort of pewter-blue background color is going to apply to all of the layouts.
01:21The headers look very similar and have very similar styling. The font usage is consistent throughout.
01:26A lot of the background colors are the same. A lot of the text sizing is the same.
01:32And I would really probably go through and I usually just catalog all this.
01:36I'll create a little sheet and I'll start making notations or I'll write things down
01:39or I'll type them in, and I'll really start thinking about, okay, what is going to stay
01:43consistent all the way across all of our layouts.
01:46For example, the Our latest galleries headline here with the line underneath it, I notice
01:51that that's the same in all three of them and in two of them it contains an icon.
01:56So maybe those are things that I don't have to write the style three separate times in the
02:01layout, but I can go ahead and write the style one time, and then if I don't need an icon,
02:05for example, just maybe go into that mobile one and tweak the change a little bit by centering
02:09the content and removing the icons.
02:10So those are things that I am always looking for.
02:13How can I make my code as efficient as possible?
02:16All right, so I am going to switch back over to my index.htm file from the 02_02 Exercise
02:25File folder. And now, because I am using Dreamweaver, one of the things I really like about Dreamweaver
02:30is, if I open up a file like the index file, any related external CSS file is available
02:36to me right here. I can just click and begin working, and I can switch back and forth between
02:40my CSS and my source code, and that is awesome.
02:43Not all code editors have that.
02:45So if you are using a separate code editor, you want to open up the main.css, which is
02:49found in the _css directory in the same exercise file. So you just want to make sure you have
02:54access to both of those.
02:56Now, if I switch over to main.css, I can see that there is actually a good bit of code in here already.
03:01I have all of my font-face declarations for the web fonts that I am going to be using.
03:06Then I have what I call my global styles.
03:07I start off every single project this way. I'll create this global styles section, and
03:12inside that I am going to have styles that apply to everybody and everything.
03:16So the element reset, the html reset, things like the display rule, Nicolas Gallagher's
03:22wonderful micro clear fix-- I use that all the time.
03:25And then after I am done with the boilerplate stuff that I have in all my projects, then
03:29I come down and start thinking about individual things.
03:32You will notice that here, I am setting global style for links and hovering over the links,
03:36and for focus so that items will look the same across browsers, how images should be
03:41treated within links, that sort of thing.
03:43I can go into some of the more specific things, like individual elements on the page and how
03:47they should look across devices.
03:48So this allows me to kind of build sort of a building block, and what I would do at this
03:53point is, after I have identified all of those sort of similarities between the different
03:58page layouts, I would then start going ahead and coding those similarities in. So that's
04:02what I want to do now.
04:03So I am just going to go down, and just to give you an idea of kind of where we are at
04:06right now, if I preview this page in a browser, this is what it looks like.
04:09All right, so yeah, not great, but here is the thing to remember.
04:13This actually is a responsive layout.
04:15It changes based upon the screen size.
04:16It expands to fill full screen when there is room for it, and when there is not, it
04:21will go down to any screen size that I want.
04:24So that's one of the good things about pure HTML:
04:26it is very responsive.
04:26All right, I am going to go down to the very last rule and I am just going to create a
04:30HTML selector, and then I am just going to do background for that. And the background
04:35is going to be color, so I am going to do rgb, and inside that 123, 121, 143.
04:41So of course, I've already taken a look at what those colors need to be. As a matter
04:45of fact, if you look at the top of the styles, you'll see a color guide up there that you
04:48can copy and paste those values from.
04:50So that's going to be consistent no matter what layout I am working with.
04:53Underneath that, I am going to do the body element, and inside that I am just going to
04:57do a font declaration of 100% Cantarell, which is our web font that we loaded up using
05:04@font-face above that.
05:05I'll give it some fallbacks of Arial and Helvetica, and then finally, sans-serif.
05:14So that's going to be consistent across my page.
05:16I want to give the elements a starting line height of 1.5.
05:20That'll inherit down to all the elements.
05:21I am going to go ahead and give my body a background of white. You can use #fff if you
05:29wanted to. And then the color, just the default color of all the page elements, I am going
05:34to do rgb (76, 67, 65).
05:41And then for font-weight, I am going to do normal, and font-style, I am going to do normal.
05:48So that, in a lot of ways, is kind of a reset in and of itself, because I am saying, hey,
05:53I don't want anything be bold. I don't want anything to be italic.
05:56That way I get to go ahead and control all that.
05:58You don't necessarily need to do that; you might want, for example, to make sure that
06:02italics are being applied where they are, but that's just a way of sort of making sure
06:05it's sort of resetting everything for me.
06:07Now, that doesn't mean that the strong tags or emphasis tags won't be bold or italics;
06:11they will. But this is just going ahead and sort of establishing the even playing field
06:14for everything else.
06:15All right, the next thing I want to do is go into some of the individual regions,
06:19so I am going to do #mainNav h2, so I am targeting the heading two (h2) inside that #mainNav.
06:26And for that I am going to do a display of none.
06:28Now if you are wondering, what in the world is that?
06:30If I go back over to the source code and I look inside my #mainNav, you can see that
06:34there is a heading 2 (h2) right there that says Site navigation.
06:37Now, that's there for two things: accessibility purposes, so that people that are looking
06:41at this know that it's a site navigation, and also for document outline generation
06:45so that the navigation doesn't come up as an untitled section;
06:48it will come up as site navigation.
06:50So obviously visibly, I don't really need that in any of my layouts, so I am just going to
06:53put that display:none.
06:54The next thing I am going to do is nav ul, and I am going to do list-style equals none.
07:01So, again, I am just doing a nice little reset here. If I find any type of an unordered list
07:05inside of a nav, it's a list of links and I don't want it to look like a normal list,
07:09so I am just turning the list styling off.
07:11Now I am going to go into another, a very specific region, and that would be the header,
07:14so I am just going to do header styles. And I like placing a comment above these regions.
07:19Again, I lied about using some of the Dreamweaver's tools. Some of them are so easy to use.
07:23But I am just going to place a CSS comment there for header styles, which is nice, and
07:28inside that I am going to do the header element itself. For that, I am going to give it a background
07:33of rgb (198, 98, 102). For width, 100%. Make sure it stretches across all layouts.
07:46Padding at the top, we're just going to give it 1 pixel, and that's so I can have a little bit
07:51of margin control and there is no margin collapse above it.
07:54For overflow, I am going to do hidden and for margin-bottom, 1.5 ems. So it's going to
08:01be consistent across devices as well. Because I am using relative units of measurement of course,
08:05it will look a little bit different on each one, but it's consistently spaced,
08:08so it has that same visual relationship.
08:10Then I am going to start going to the individual elements within header, so I am going to do
08:13header h1, and for that I am going to change its color to white.
08:19I've really taken, recently, to using these keywords for white and black and things like that.
08:24For font-weight, I am going to use bold.
08:28For text-transform, I am going to use uppercase.
08:32We are almost done with the header.
08:35I am just going to do header a, so transforming any links found inside the header.
08:40I am going to do a text decoration of none, stripping out any default link styling.
08:46For border, I am going to choose none, again stripping out any borders that might be applied, and
08:50for color I am going to choose white.
08:51Now if you are wondering about this, the link is the actual company name, that desolve,
08:56so I really don't want any link styling.
08:58I want people to be able to click on this and go back to the index page, but I don't
09:01necessarily want it to stand out as being a link.
09:04So for the same thing, I am going to do header a: hover, and I am going to strip out any default
09:09hover styling that might be applied to it.
09:11I am just going to do border of none, color of white.
09:15All right, if I save this and preview this page in my browser again, I get not a lot of
09:23change, but a little bit.
09:25The text sizing has changed a little bit. The colors have dramatically changed. My heading,
09:29the text looks the way I want it to.
09:30There is a link up there. It's got the same color.
09:33So that type of consistency I have sort of established all the way across the board.
09:37Now, if you were to go in and open up the index or the main.css file in the finished_files
09:42folder, take a look at exactly how much styling can be done with global styles.
09:47So after the header, I add some styles for #mainNav.
09:50I have the mission. I have article styles, gallery, that sort of thing.
09:53So take some time to go through those.
09:55If you want, you can copy and paste them in or you can kind of play around with them yourself.
09:59Some of the stuff you may not recognize, like this data url. If you see this, don't flip out.
10:04It's fine. We'll talk about some of the stuff a little bit later on too.
10:06But I just wanted you to get a feel for exactly how much control you can use for global styles
10:13over the course of a multiscreen layout.
10:16Too often, I see people that are brand-new to doing responsive design try to basically
10:21cram everything into each layout--desktop, tablet, mobile--and they end up with a really
10:27bloated style sheet.
10:28They end up basically with the same style sheet replicated three times.
10:32You don't need to do that. You can create these global styles and then just create the
10:36smaller layout-specific styles within the media queries that we are going to be creating
10:40a little bit later on.
10:41Now, take the finished file and preview that, and you can see, again, we've added a little
10:46bit more content to that that's going to be consistent across the layouts.
10:50So just remember, having as much of your styling as possible in a set of global styles like
10:55these that are going to apply to every single version of your layout,
10:58it's going to be a lot easier to write, as you are writing less code, and it's going
11:01to create a more manageable site in the long run.
11:04However, I do want to point out, it does require you to develop a more thorough planning process
11:09and put a lot more time into the initial planning of our styles. But in the long run, I feel
11:14that the benefits that you gain from this approach are well worth it.
Collapse this transcript
Determining content breakpoints
00:00Designing for multiple screens often means you're going to need to create several different
00:04versions of the same layout, each one optimized for a range of specific screen sizes.
00:10One of the most common responsive design questions I get is, which devices do I need to target,
00:15or which devices should I target when planning layouts?
00:18To me, that's the wrong question.
00:20It's really not a matter of devices. Now, let's be honest.
00:23Those just come and go all the time, and there's already way too much diversity in terms of
00:27the different ranges of screen sizes to really make targeting the devices themselves practical at all.
00:33Instead, I recommend letting your content determine when to alter your layout.
00:38So to demonstrate this, I have the breakpoint.htm file open, and you can find this in the 02_03 directory.
00:43And what we have here is a very simple three-column layouts.
00:48Now I've three versions of this layout.
00:49Let me preview this in the browser so that you can see it.
00:53We have our three-column layout. You'll notice the left column is a lot wider than the other
00:57two. And then I have a version of this layout that's a two-column layout, where the third
01:02column breaks down below these two, and then I have a single-column layout.
01:05And essentially three-column layout is going to be for larger or desktop screens, if you will.
01:10The two-column layouts can be used for medium or tablet screens, and then the single-column
01:15would be for smaller or mobile screens.
01:18You'll often hear people use those terms kind of interchangeably--desktop, tablet, and mobile--
01:22and I'll use them throughout this course as well.
01:24But I want to point out that just because something is a certain size, doesn't mean
01:27that somebody is viewing it on a tablet.
01:29There are a lot of netbooks or chromebooks out there that have those small screens that
01:33aren't really tablets. Same thing for phones. You've got phones that are now so big
01:36they're certainty into the tablet category.
01:38So you can't really pigeonhole that way. So I try to use screen sizes as much as I can,
01:43like small, medium and large, but I found myself falling back to that terminology quite frequently.
01:48Okay, so again, I could go ahead and just define sizes and say well, you know what,
01:53an iPad is this size, and the iPhone is this size, so those are the values I'm going to
01:56use, but there are so many other devices out there, Android devices and so many tablets
02:01and laptops that are changing sizes, that if I just target one range of devices, I'm really
02:06setting myself up for failure over a wider audience.
02:10So what I'm going to do is, I'm in Firefox, so I'm going to turn on Firebug.
02:13If I was in Safari or Chrome, I could turn on the WebKit Inspector.
02:16If you're in Internet Explorer, you can turn on the Microsoft Developer Tools.
02:20And really, what I want to do is just sort of target the page itself, so I can see what
02:24size my browser window is when my layout starts to fail. That's really what I'm looking at here.
02:30So what I'm going to do is I may come over and target my HTML element and go to the Layout
02:35tab here, and this is going to give me a nice little report on what size my browser window is currently.
02:40Now, I'm dealing with Chrome here, so this isn't 100% accurate, but it's close, and you
02:44can make some determinations here.
02:46So I'm just going to start resizing my browser window. And I'm really not even looking at
02:51that value. What I'm looking at right now is at my screen.
02:54And I'm starting to look at these columns, and there are really starting to fail.
02:57I notice that the headline just broke on me. The columns are getting a really thin.
03:01It's kind of hard to read that middle column now.
03:03So right in this range right here, I'm starting to see a failure of the layout.
03:08Now of course, I'm just using a very simple three-column layout here.
03:12But if I had a more complex design-- and of course, this layout is also fluid.
03:16That's another thing: you need a flexible fluid layout to really test this.
03:20I can really see where this layout starts to fall apart.
03:22And looking down at my console down here, right at about 846 pixels--so I'll just round
03:27that up and say 850.
03:28So my first breakpoint is now at 850 pixels.
03:31So if I go back into my breakpoints file, you'll see that I've got a couple of media
03:35queries that are just commented out, and I'm going to uncomment those.
03:39Now, don't worry about the media queries syntax
03:41if you've been ever dealt with them before. Later on in this chapter we're going to have
03:44an entire movie dedicated to media queries.
03:47But what I'm going to do is, for the second layout, which is the two-column layout, I'm
03:51going to change that max-width value to 850 pixels, because that was my first breakpoint,
03:57so maximum width of 850 pixels.
03:58All right, so I'm going to go ahead and save this.
04:02Now I'm going to go back into my browser and refresh.
04:06And I'll notice now that as I start to resize this, once that layout starts to fail, instead
04:11of allowing layout to fail, it now breaks down to a two-column layout.
04:15You can see that now the third column falls below those guys, but when there's enough
04:19space for it, it expands out and I get my three-column layout.
04:22So that's letting the content dictate where the breakpoints occur, not so much any one particular device.
04:28Now, I could take this a little bit further.
04:30I can come in and say okay, what about this two-column layout? When does it begin to fail?
04:35And when I start getting into this range right here, again, that beings to fail a little
04:38bit. It's getting really, really skinny over there on the right-hand column.
04:43So, I'm not crazy about this section.
04:45So I'm thinking at about, probably about 570 to 580 is probably where I'll set this one.
04:51So I'm going to go back into my index file, I'll uncomment out the last media query, and
04:59you'll see this one has already set to 570.
05:01What these media queries allow you to do is to establish these trigger points.
05:04Now, of course the media queries--we will go over the syntax a little bit later, but
05:08it's important that they deal with the proper ranges. For this one for this example, I'm saying hey,
05:13the maximum width of this particular layout should be 570 pixels.
05:17And then this one is saying the maximum width is 850.
05:19So actually, these will apply to both of these. So we really don't need that, so I need this
05:24one to be more of a range.
05:26So I'm going to say and here, I'm going to do a min-width and I'll give it a minimum
05:31width of 571, just one more than the maximum width down below it, and then chain together another and.
05:37These expressions you can chain them to together to create these ranges here.
05:41So now I can save this and essentially what we have is we have a default layout.
05:46That's our three-column layout. And then between the screen sizes of 571 to 850, we're going
05:51to get a two-column layout, and then below 570, we'll get a one-column layout.
05:55So after saving that I'll go back into the browser, refresh my page, and we can see that in action.
06:00As a matter of fact, I am just going to close this. We don't really need to see the window size anymore. And what
06:04I'm going do is just resize this browser. You can see, once it falls below 570, I get
06:07a single-column layout.
06:09So that would work well for smaller screens, mobile devices, things like that, all the way
06:13down. And then once it has enough space, it gives me a two-column, and once it has enough
06:16space again, I get the three columns.
06:18So that's one of the things that media queries will do for you, and we're going to explore
06:21those in more detail a little bit later on. Following that type of workflow where you're
06:24letting the content drive your breakpoints, it's going to free you from wondering about
06:28a specific device or having to redesign your sites as devices evolve or gain popularity or fall out of favor.
06:35Now, although you still need to think about devices when you address functionality, with
06:39layout you can simply focus on content and breakpoints and be confident in the fact that
06:44your layouts are going to look great, regardless of the screen size.
Collapse this transcript
Defining media queries
00:00So in the previous exercise we discussed setting breakpoints and used a couple of media queries
00:05to control multiple layouts.
00:07In this exercise we're going to a little deeper into media queries and we're going to set up
00:10our initial structure for the desolve.org layout.
00:15To do that, I'm going to be working in the main.css file, which you can find in the 02_04
00:21exercise folder, and then inside of that, the _css directory.
00:25So this is pretty much where we left our CSS file the last when we're working on it when
00:29we set some global styles. If I scroll down for example,
00:36I can see the last global style deals with page footer, and that's just another workflow that
00:41I forget to mention it to people, and it's fairly common--most of you probably work same way.
00:45I typically will write my styles in the order that they're found within the source order,
00:50so the header styles will come up first, followed by whatever is in the HTML code, and then page
00:54footer is at the bottom. And it's just so much easier for me to find styles and to avoid
01:00certain styling conflicts by doing it that way, so that's typically how I'll do that.
01:03So what we're going to do is we are going to go ahead and put in the skeleton in place
01:06for our responsive layout by going ahead and just building our media queries.
01:11So the first thing I'm going to do is I like to comment out regions, so I'm just going
01:15to do a little bit comment here. And I'm going to do mobile styles, and I think I'm just
01:19going to hit Enter a few times, just so that's a little further up the screen. It's not
01:24the best thing in the world to do, but it makes it easier for your guys to see when I was typing this.
01:27So I'm just going to say mobile styles, and then after that I'm going to do a media query.
01:31And I'm just going to do @media only screen, and then I'm going to pass an expression
01:40(max-width: 480 pixels). And then after that I'm going to open the curly brace, hit Enter
01:47twice, close the curly brace. Okay, I'll give you a second to do that, and then let's talk about syntax.
01:54One of the things that I want to mention here is that we are going to be using inline media queries.
01:59There are two ways that you can do them.
02:01You could go ahead and do them inline like we're doing here, using an @media block, which
02:06is going to be just in line right with the rest of your styles or--and I'm just going
02:10to open up one of the HTML files. You don't have to do this, but you can also do a media
02:13query here in a link tag that's linking to a style sheet. So the same decoration here that
02:19we have screen and projection, we could also go ahead and do a media query, only screen and,
02:26and then you could just go ahead and pass in max- width or whatever value you want to use, 480 pixels.
02:33So that would do the same thing. That would work just as well.
02:37Now, the difference here of course is that you would need a different external link for
02:42every single one of your media queries, and we're going to have three of them. So that's
02:46three additional external resources, and that's going to add a lot more overhead to your responsive
02:51project, because when you get down to smaller screen sizes, especially on mobile devices,
02:56every single request you make to the server is a dramatic increase in overhead. So you
03:01want to reduce the server requests if you can. So I'm going to close that. I don't want to save it.
03:07So I just want to demonstrate that.
03:08In my opinion, using the inline styles is a much nicer and safer way to go in terms of
03:15organizing your styles, maintaining your styles, and also reducing the amount of requests you
03:19have to the server, I really recommend using @media block. But once you establish an @media
03:24block, now you're passing in the actual media query itself. Let's take a look at the syntax.
03:29Now, first thing you're going to notice is the only keyword. Now, this keyword is actually
03:32optional. We don't have to use that.
03:35It's really kind of the way of filtering out your media queries for browsers that don't
03:40understand a media query.
03:42They'll run into that only keyword, they won't understand it, and they'll just stop parsing
03:45that particular block.
03:47So that's a way of sort of filtering those styles out.
03:49It's the only purpose it serves.
03:51It doesn't really need to be there.
03:52I'm placing it there just to make sure that we're sort of hiding it from nonconforming browsers.
03:57All right, next we can pass any media type that we want: screen, projection; whatever you
04:01want to do, you can go ahead and do that.
04:03Now, you can still do a comma-separated list, so if I want to do screen and projection, I
04:07can still do that, but the syntax would be a little different, because the comma would
04:10come here, after the expression. So we could go ahead and put a comma there and then we
04:14could do projection too, if we wanted to do that.
04:17All right, then, after you have your media declaration, you use another keyword, in this
04:23case and. There's also a not keyword, and the not keyword basically does the opposite.
04:29So it's really tricky to get your mind around using not and it can leave the some really
04:33unintended side effects, but essentially if you not, you're telling the browser, or whatever
04:38the user agent is, to go and apply these styles everywhere except for when this evaluates
04:42to true, so think about that.
04:44All right, so and is a way of chaining these expressions, and I can have as many expressions as I want.
04:50I could just say and, and, and, and, and I can just keep stringing them together.
04:53In this case I'm going to maximum width. You have a lot of different things that you can check for.
04:57If you go to the specification on media queries, you can read up more about these. You have
05:01height, you have width, you have color, you have grid.
05:05I mean there's all sorts of things inside there that you can use.
05:07Now most people are using width and height. And in terms of width and height, there is
05:11also a lot of properties that will allow you to do a minimum or a maximum prefix, and
05:16width is definitely one of those.
05:17Now that's very helpful, because what we're doing here, if we read the syntax correctly, we are saying
05:21hey, go ahead and apply to any screen device, any screen media device, who's maximum width
05:26is 480 pixels. So 480 pixels and below are going to get the styles applied to them that
05:31we placed inside the media query. Anything above 480 pixels will not apply.
05:37So those are our mobile styles. It's a basic introduction into media query syntax.
05:41Let's go ahead and write our other two media queries. All right.
05:43So after this one on a line just sort of below here, I'm going to go ahead and do a
05:46new comment, and here I'm going to go ahead and do new tablet styles. And you can copy
05:52and paste if you like.
05:53I think typing it sort of gives you a nice bit of practice, so I'm going to do @media
05:58again, and here I'm going to say only screen and minimum width of 481 pixel.
06:06Notice that I'm being very careful to not have any overlapping values here, so I wouldn't
06:10say minimum width of 480 pixels, because then the media query above and this media query
06:15would apply at the same time, and I would have all sorts of styling complex.
06:19Now in this case for tablets we really want to establish a range of screen sizes, not just
06:24a minimum value or a maximum value, but from between these two sizes I want these tablets
06:29to apply. And that's one the nice thing about being able to chain these together, because
06:33all I have to do is do another and, and this time instead of minimum width, do a maximum width.
06:38And here I could go ahead and pass 768, which is going to be our next break point, and then
06:43I can go ahead and open up a curly brace, close it again, and now I have my tablet style.
06:47So this one is going to apply anytime the screen size is between 481 pixels all the
06:51way up to 768, we're going to get our tablet styles.
06:55After that we're going to go ahead and do desktop styles, and so even here I'm doing
06:58tablet, mobile, and desktop even though, you know it's not really that.
07:01It's applying to any screen of that size, so there is no device that it actually going on whatsoever.
07:06Again, we're going to an @media block only screen and, and here we're going to do a minimum
07:13width of 769. So again, notice how I am being very, very careful to make sure I'm not passing
07:18the same value I use before, and I'm going 1 pixel above it.
07:22All right, so @media only screen and a minimum dash width 769 pixels.
07:26All right I'm going to go ahead and save this, and that's gives us our skeleton.
07:31So now that we have our media queries defined and kind of outlined and structured, we can move
07:35on to starting to craft those individual layouts for each screen size range.
Collapse this transcript
Building the basic desktop layout
00:00Once you've defined targeted screen sizes using media queries, you can then focus on
00:05crafting the individual layouts themselves.
00:08Much like how I really like to structure the basic page containers in HTML first, I also
00:13like to control the layout of those page containers first, before I move on to working on the
00:18specific regions themselves.
00:20So in this exercise we are going to start that process by styling the basic containing
00:24blocks of our desolve.org desktop layout.
00:28I'm really going to be working on one file, but I have got two files open here:
00:31the index.htm file from the 02_05 folder and the main.css file. Again, because I am in Dreamweaver
00:38here, I only need to open up the index file and it gives me access to the main.css, but
00:41if you're working in a code editor that does not do that for you, make sure you open up
00:45the main.css from _css directory, because that's the file we are really going to be working on.
00:50Now, if I were to take this file right now and preview it in the browser, yeah, not awesome,
00:55but all of the information is there.
00:56So now we are ready to go ahead and start building the layouts themselves.
01:00Now, if I switch over to the main.css and I scroll all the way down towards the bottom,
01:05here we can find all of our individual media queries that we built in the last exercise.
01:09Now, I want to talk about theory here--or at least an approach to this.
01:13I see a lot of people who will start out with the layout being the desktop layout and then
01:19add the media queries to convert the layout to tablet-based or mobile smartphone-based layouts.
01:25There's also a movement underway that's gaining a lot of popularity where your default layout
01:30is the actual small screen or mobile layout, and then you use media queries to modify that
01:35layout into tablets and desktop sizes.
01:38Either one of those approaches works really well.
01:40I actually like the mobile-first approach a little bit better because what that means
01:44is if your media queries fail, at least smaller screens will still see a mobile device.
01:50Media queries are pretty well supported among modern browsers,
01:52so you can be pretty sure that they're going to display the layout the way you wanted to
01:57at those larger screen sizes.
01:59Now, that being said the way, the way I'm approaching it is that my global styles really don't have
02:03very much, if anything at all, in terms of layout. And I have three separate media queries,
02:09one for mobile, tablet, and desktop.
02:11Now in this case, this is more of an organizational thing and a teaching tool than it is the way
02:16I would actually deploy this.
02:17I would probably build my mobile styles to be the default styles and then go ahead and
02:22enhance that to tablet and desktop.
02:24But there are plenty of projects I work on where I do it this way, where each layout
02:28is an individual layout.
02:29So it's really a personal preference in kind of how you want to build it.
02:32Okay, now I am going to do things a little bit differently in this particular movie, and
02:36one of the things I am going to do little differently is instead of having to watch
02:39me type all of these selectors,
02:41I am just going to paste them in, and when I do that, I'll go over the syntax.
02:45So when you see me paste a selector in, pause the screen for a moment--and as a matter
02:49of fact, I am going to do the thing I did a minute ago, where I give myself a little bit
02:52of room, so it's easier for you guys to see these.
02:54I will go back and delete that extra space a little later on. But when I paste in a selector,
02:58just pause the movie, type it in--what you see on the screen--and then I will go over
03:02the syntax and talk about what it is.
03:04So that gave us a little bit of time and you won't be subjected to all of my typos.
03:07All right, so the first rule that we are going to do in the desktop styles--I should have
03:12mentioned that as well.
03:12We are going to go in to the desktop styles media query. And the first rule that we are
03:16going to do is the body selector,
03:18so go ahead and pause the video or type this in as I am talking about it.
03:23So what we are doing with the body selector for desktops is we are setting the width to 90%.
03:28So on our desktop sizes, the page layout will take up 90% of the screen.
03:32We are giving it a margin of 0 for top and bottom, auto for right and left, and that's
03:36going to center it.
03:37And then--and this is really important part of this--although we have a percentage, which
03:42means we have a fluid layout--meaning no matter what size, it could be 90% of that--
03:46we are establishing a range by using a minimum and maximum width values for this layout.
03:51Now, minimum width and maximum width aren't supported in every single browser, but they're
03:55widely supported in desktop browsers. And it's safe for me to put it in, because even if
03:59they are not supported, I still get a 90% width.
04:01So this is just a way of me saying, okay, I want a fluid layout, but I only want a fluid
04:05layout within this range.
04:08So once it starts getting smaller than 1024, it will stop. Once it gets as wide as 1280,
04:13it will stop as well.
04:15Now earlier, I talked a lot about letting content determine your breakpoints, and I found that
04:19when I started taking this particular layout below 1024, portions of it started to fail,
04:24so that's one of the reasons why I'm sort of restricting it to that minimum width.
04:29Okay after that, I am going to go in to start targeting the specific regions.
04:32I am going to start with the header styles. And what we are doing with the header selector
04:36here is we are just setting that height to 165 pixels. That's a very top element, and it
04:41allows me to put in the logo and the branding all of that have the height that I need.
04:46After that, we are going to go in and we are going to concentrate on the mission statement section,
04:50so that has a class of mission applied to it. And that is going to give the mission
04:55area a height of 350 pixels, a padding left of 3.9%.
04:59Now, the padding was determined early on in my layout process. You may have remembered
05:04that from the dissolve mockup where I was talking about how much padding I am going
05:08to need on some of these elements.
05:09And that's determined by a percentage of its parent element.
05:12So it's really going back to that body and saying okay, give me 3.9% of you, and that's
05:16giving me my gutters that I am looking for on the sides.
05:19Turning overflow to hidden, and for background, I am going out to the images folder and I
05:24am finding that gallery_banner, and then I am giving it a 4em margin-bottom.
05:28So it's going to be quite some distance between that and the next element.
05:31And I am giving it relative positioning because some of the contents inside it are going to
05:34absolute-positioned, so I want the parent to have relative position so they are positioning
05:38themselves relative to mission and not another element.
05:40Now, you may have noticed that I skipped over the Nav styles. If you are wondering about
05:45that, throughout this entire chapter, we are going to do pretty much everything except
05:48for the navigation, and that's because navigation has its own separate chapter after this.
05:52So we will focus on creating and styling our navigation in the next chapter.
05:57Next up is going to be our article styles. And that actually has two selectors,
06:02so let me move the back up and you can pause that and go and type these in. And what this
06:07is doing for us is, notice that we are creating a two-column layout.
06:11We have a section that has our main content inside of it and then inside that section,
06:14we have an article and the aside.
06:16So we are taking the article and we are floating it to left. We are giving it a predefined
06:19width that determined very early on in the planning process.
06:22We are giving the same padding left so that there is same amount of gutter between the
06:25two columns as there is on the side of the page. And then the sections inside the articles,
06:30we are going ahead and giving them a margin bottom and a border on the bottom as well,
06:34which is going to give separation between different sections within that article.
06:38After my article styles, we are going to go ahead and do our aside styles. And just like
06:44the articles are floating to left, the aside is floating to right.
06:47It's going to give us our columns.
06:49It has a width of 19.1%. Again, we predetermined that when we were doing our mockups. And we
06:53are giving it a padding right as well as 3.9%,
06:56so all of that is consistent all the way throughout.
06:58Last thing left to do is our footer styles.
07:00So there's my page footer.
07:01You will notice that for this rule, we are doing clear_both, so we are reestablishing
07:06normal document flow after the two floats above it.
07:09We're setting overflow to hidden, and we are giving it a fixed height of 150 pixels as well.
07:13So all of this empty space down here, I don't really need it.
07:16And again, all we're doing right here is doing the basic layout for just the parent container
07:21elements; we are not controlling any layout of the stuff inside of it.
07:24If I save this, go back into my browser, and refresh,
07:27at this size, you will notice that we begin to have the bare bones of our layout.
07:31Here are two columns. It's working good. We have got the banner graphic in there. Our header
07:35is the size we want it.
07:36Here's our navigation again. We really didn't do any styling of our navigation. And if I
07:40resize the browser window, you'll notice that at a certain point that layout fails and we
07:46go back to a single-column layout.
07:48So once we hit our breakpoint, there's our two-column layout coming into focus.
07:52All right, I wouldn't say it's looking great right now, but we do have the basic structures of it in place.
07:58So with the desktop basic structure in place, in our next exercise, we are going to move
08:02on and tackle the tablet layout.
Collapse this transcript
Building the basic tablet layout
00:00In our last exercise, we defined the basic page region styling for our desktop layout, and
00:05we'll go ahead and continue working on our basic layout structure by tackling our tablet
00:10styles in this exercise.
00:12So, again, I have the index.htm in the main.css file open, and you can find these in the 02_06
00:19directory. And we're going to work pretty much the same way we worked before.
00:23I'm just going to paste some code in and then talk about it, and as I'm discussing it,
00:27you can pause and type the code in.
00:29We are going to be using pretty much the same structure we use before, so the selectors
00:33are going to be almost identical.
00:35So what I really want to focus on when I talk about these selectors are the differences between
00:39the tablet layout and the desktop styles layout, and kind of identifying what makes
00:44that tablet layout a little bit different from desktop.
00:46Now first off, notice that the tablet layout is only going to apply between 481 pixels
00:52to a maximum width of 768 pixels.
00:53So, the first thing we do is go ahead and paste in the body selector here, and you'll notice
00:58that just like the desktop, its width is 90%, and it's using the auto margin technique to
01:03the center of the page as well. But the minimum and maximum width values are much different:
01:08500 pixels for the minimum width and maximum width is 768.
01:12So what that means is essentially, it's going to flex between those two. After 768, it's going
01:17to jump up and hit the desktop styles and it'll change layouts, but from 500 all the
01:21way down to 480, it's going to remain rigid at that size. And again, that's our point of
01:25letting the content determine where those breakpoints lie, even within screen size ranges like that.
01:31After that we're going to go ahead and do that header styles.
01:34Now this header style is going to be 165 pixels, which is exactly the same as last one.
01:38I can scroll down and show you guys that.
01:39Now so this is an instance where you might look at this and say, well, is that something
01:43that I can move into the global styles and then overwrite because mobile is a little
01:46bit different? Could I do that?
01:47And yeah, you certainly could do that, but again, a lot of times it's a judgment call,
01:51and in this case this gives me the flexibility, if later on down the road I have decide to
01:56make one of these headers a little bit a different, I don't have to create a new selector; I can
01:59just go ahead and use these or start adding to and modifying these selectors.
02:03So remember, right now we just focusing on layout. We are not focusing on the things
02:06that might go into that header or the styling that might be different within the header.
02:11So, sometimes you're going to see some similar selectors that you might want to tweak a little
02:14bit later on. So it's always a judgment call as to whether you're going to make it a global selector or not.
02:19Now again, remember, we're skipping over the navigation styles, because we're going to
02:23come back and work on them in the next chapter.
02:26So what we're going to do right now is work on mission. That mission div tag with the
02:30mission class applied to it,
02:31I have got a padding left of 3.9%, which is exactly the same I had before. overflow is
02:36hidden, position's set to relative. The margin bottom is little less because I have a little
02:40bit less screen real estate at this screen size, so it's 3ems.
02:44But the background is really where I want to turn your attention to. You'll notice here,
02:48instead of requesting that large banner graphic that we requested before, this time we're requesting
02:52a smaller skyline graphic. So it's the same image; it's just smaller in size, and that's
02:58a really important part of responsive design, in terms of using this background images in this way.
03:03What that's really doing for us is it's lowing the overhead required for those tablet devices
03:08and phone devices which are sometimes connecting over networks that aren't quite as fast, or
03:12maybe a cellular connection. So it's lowering the file size required here. We could have
03:17taken that larger graphic and then just scaled it down the screen size, but then we'll
03:21wasting pixels. We don't really need them.
03:23So by going ahead and requesting a separate graphic here, a slightly smaller graphic, we're
03:27actually being a lot nicer in terms of resource management. And this is a technique that a lot of people use.
03:33Now, one thing I want to point out about this. In Android 2.3 and below, Android devices will
03:39go ahead and ask for every single background image, even in ones that media quires that
03:43don't quite apply. So the desktop one would be downloaded as well.
03:47But for most all other mobile devices and any Android devices above 2.3, which is the
03:51majority of them now, this technique works just great, and you only get the background
03:56images in the media query that's active at the time.
03:58So it's a great way of saving file size and lowering some of the HTTP requests that you
04:03might be making over those cellular networks. So this is the technique that you should use
04:07for a lot of your images.
04:09Now it only works for background images, so this is pretty much a technique that's limited
04:13to those decorative images that we've been talking about.
04:15All right, after mission, we're going to go ahead and do article. Again, we have two selectors
04:20for article. Our first one I want to concentrate on, and that is the generic article element.
04:25Now you notice in the last layout, the desktop, which was the two-column layout, the article
04:29was floated to left. This time there's no floating going on,
04:32so we are back to a one-column layout. The width is 92.2, but I have the 3.9% right and left
04:40padding, so essentially, that's giving me that sort of margin or the gutter, if you will, on
04:44either side, and then the width is fluid within that page range.
04:48The article section still has the border on the bottom, and notice that the margin on
04:52the bottom is a little less than it was on the desktop.
04:55I'm using the same amount for our margin bottom as I am for the padding on the bottom.
04:58Now what that's going to do is it's going to give me equal amount of space above and
05:01below that border between these elements. So it just acting as a separator between those
05:05sections. We also aren't turning the overflow to hidden and adding a position of relative
05:10so we can use absolute positioning inside of that.
05:12After article, we're going to use asides, and for the asides, again we're doing the same
05:17thing here. It's a one-column layout, so we're not floating these to the right. We're doing same
05:21width 92.2%. We're using a 3.9% padding to be equal, so we have that same sort of
05:26margin or gutter, if you will, on the right and left sides.
05:29And then for the sections inside the aside, since we're not doing any floating, we are
05:32going to be clearing those out so that we do have a single column and we don't have
05:36any floats going on.
05:37Finally, we're going to do a footer styles, and for our page footer, even though we don't
05:42have any floating above it, I am just going to leave that clear both in there.
05:45It's just kind of a nice-to-be-sure-type thing. We're turning overflow to hidden, and the height
05:50of this is to be 150 pixels.
05:52Now if I go ahead and save this, go into my browser, and notice that I have resized the
05:56browser so it's going to trigger that tablet styling, when I select that I get a single-
06:00column layout. You can see the separator between these items, giving me enough the same space
06:05above and below it, and then I have got a little bit of styling going on here down the footer.
06:09So it's really just the basic bare bones of this layout.
06:12Now again, to see our media queries in action, all I have to do is resize the browser and
06:16once we hit the desktop, we're getting a two- column layout. Once we go below the desktop,
06:21we're getting the single-column layout.
06:22So, the basic structure of those two were is in place. The next thing we need to do is
06:26tackle our basic mobile layout, and we're going to tackle that next.
Collapse this transcript
Building the basic mobile layout
00:00We'll finish styling the basic page regions of the layouts by turning our attention to our mobile styles.
00:06Now, pretty much here, we're going to follow the same thing that we did in the previous two exercises.
00:10I'll paste some code in, and it's going to follow pretty much the same structure we did
00:13before, in terms of the regions that we will be styling.
00:16And again, I'm just going to focus on the differences between the mobile styles and the tablet and
00:21the desktop styles. So we're going to start in our mobile styles. The first rule, as it has been in the past,
00:25is going to be with the body selector. And if we compare that one to the one right underneath it
00:30there for the tablet, you'll notice that the width is the same, 90% for both of those. We're using
00:34auto margins for the center, but again we're defining that sort of range of motion, if you will, into the media query.
00:41So 320 pixels wide is going to be as low as it can possibly go,
00:45and as wide it's going to be able to go is about 480 pixels, so that's going to be our mobile layout.
00:50Now what's interesting about this is you know I talked earlier about how you definitely
00:53want to target content based on screen sizes not devices, and in the past, these values
00:58would almost target iOS precisely, the iPhones specifically, because 320 would be portrait
01:05and 480 will be landscape. But with a new iPhone 5 the landscape is much wider than 480.
01:10So again, as these devices begin to evolve, you can't count on those ranges
01:15of being accurate for each one of them, so you might as well go ahead and let the content
01:19decide exactly when it should break and not worry so much about the device.
01:23So after the body, we're going to do our header styles. You'll notice that these are a little
01:26bit, a height of 70 pixels instead of 165 we have had earlier.
01:30Again, whenever we're dealing with the smaller screens like this, we have much less screen
01:34in real estate, and not only just side to side, but top to bottom as well. So you'll
01:38notice a lot of these values are compressed when compared to the desktop and tablet.
01:43The mission styles for this one--again we're skipping over the navigation styles--but mission
01:47styles, we're setting the width to 90%.
01:49Notice that that's a little different. Instead of being at that 92% and then the 3.9%, what
01:54we're doing is we're just setting the width to 90%, setting the margins to auto, which
01:58is basically going to give us a 90% part of the window and then 5% on either side for margins.
02:05So that's fine. And then put a margin bottom on the 2.4, which is a good bit higher than
02:10some of the other ones.
02:11And it just because we're not using an image for that one, so we've got a little bit more
02:14space available to us there. We're not using a background graphic for that area.
02:18Okay, our article styles, let me scroll up here. We have got two selectors. Again, we have article.
02:24Notice that pretty much all these container elements have the same values: 90% for width
02:29and then we're using the auto margins to center them within the page.
02:32The section themselves, this one's a little bit different. So we still have that border
02:35bottom, and we still have a margin bottom.
02:37Now the padding is little bit different: 20 pixels here instead of 1.6ems. And we're still
02:42using overflow of hidden and position of relative because of some of the styling that's going to
02:46happen inside that.
02:48Next up, we're going to be doing our asides, so again, a width of 90% auto margins centering
02:53technique. And we're clearing the section just in case any floats happen to still be hanging
02:58around or we need a two-column layout at a small size.
03:01Believe it or not you actually do sometimes need to float stuff at those smaller sizes,
03:04so I might as well go ahead and clear those.
03:07And then finally, we're going to be doing our footer. So that didn't take quite as long.
03:11There's not quite as much going on here.
03:13It's a much simpler layout at the smaller sizes.
03:16For again, the page footer, we're just clearing things out, putting a little bit of padding
03:19on the bottom of it and then hiding any content that's overflowing.
03:21So I'm going to go ahead and save this, preview this back in the browser, and I'm just going
03:26to refresh, and you can see, here's our mobile layout.
03:29Now again, we're not really styling any of the individual content inside of it just
03:34yet, but notice we got this 5% margin on either side. You can see some of the styling
03:38coming through, the centering is coming through, and of course we can trigger each of the media
03:44queries by simply resizing the browser. There is our tablet layout and there is our desktop layout.
03:49So our basic layout regions are now styled. They're in place, and we're seeing three variations on
03:54our layout, so that's great.
03:55And notice again, notice the range of motion here. We're still expanding, we're still expanding,
04:00and it'll freeze at a certain point. Same thing when we go down. Notice that it freezes there,
04:03so that's our range of motion, and then it triggers the same thing the tablet.
04:07I have a range of motion that freezes at a certain point, and then we go down and
04:11we freeze here as well. So they're fluid layouts within a specific range.
04:17If you're wondering, I might as well just go ahead and say yes, this is indeed how I typically
04:21work, although I will admit I usually do percentages and just use placeholder background
04:26colors to make sure I have the regions correct before I really start styling any actual content.
04:30So a lot of times I'll just come in, structure basic page elements, and then style those basic
04:35page elements, get those refined before I start working on the interior content.
04:39Now here, since the content is already sort of on the page, I have got a little more color,
04:42a little typography going on, than I would normally have at this stage.
04:46So although it looks like just one big mess at the moment, we're actually a lot further
04:49along than you'd think.
04:51So in our next series of exercises, we're going to tackle refining the styling for each of
04:55the individual layouts and look at some of the considerations that you're going to need
04:58to make from screen size to screen size as you refine those layouts.
Collapse this transcript
Refining desktop layouts
00:00In our first series of exercises targeted towards styling the different layouts for
00:05desktop, tablet, and mobile, we concentrated on styling the sort of basic content regions.
00:11So in the next series of exercises, I want to talk about refining those layouts, adding
00:15a little bit of styling for the interior content.
00:18And of course, we don't have time to do the entire layout, so I want to focus instead
00:23on three very specific areas.
00:24Now currently, I have the index.htm file open from the 02_08 directory.
00:28I've also got the main.css opened from the _css.
00:31Again, since I'm working in Dreamweaver,
00:33I'm going to kind of toggle back and forth between the two of them.
00:36Now if I were to preview this in my browser right now, I can see that this is kind of
00:41right where we left off before, where we have our basic content region styled.
00:45So I want to focus on three very specific regions, one would be the header up top.
00:48This is where our branding is going to go, in terms of the logo and the company name
00:51and taglines, things like that. And then this mission area right down here where the mission statement,
00:56now this area is going to change dramatically between each of the layouts, so this is a
01:00really good area to take a look at, in terms of what's involved in transitioning styling
01:04from one layout to another.
01:07And then we are also going to focus on these individual regions here for our latest galleries.
01:10We are going to focus on styling each of the featured galleries and taking a look at what
01:14we'll have to do there for the background images and floating.
01:17So there are a lot of changes there from layout to layout as well.
01:19So not only are we focusing on the individual styles to achieve the layout we're looking
01:23for, we really want to focus on, as we go through these exercises, the differences between the
01:29desktop, tablet, and mobile styles as well.
01:30So I'm going to go back into my file.
01:33I'm going to switch over to the main.css. And again, you can find the desktop styles
01:37at around line 541, so go ahead and scroll down and find those.
01:41Again, we have a lot of selectors going on here, so rather than going in and typing this
01:44out, I am just going to paste the code in. Because there is a lot more involved in terms
01:48of selectors, I'll try to scroll back up to fit them all onscreen, but feel free to pause
01:52the video, type in the selectors, and then I'll kind of walk you through what they are doing.
01:55All right! So I am going to go ahead and start with our first section of code here in the header, which is two selectors.
02:01We have header h1 and a header h2.
02:03So I'll focus on the header h1 first.
02:05So for this one, we're setting our font-size large just for the name of the company along with logo.
02:09We are giving it enough padding over here on the left-hand side where the logo will
02:13actually fit, giving it a line-height equal to the height of the header, so it's going
02:16to vertically center it inside that.
02:18Then we'll give a little margin to the right, and that's going to keep the tagline away from it.
02:22We're floating it to the left. That's going to allow the tagline and logo to line up to each other.
02:27And then we've got a margin to the left of 3.9%.
02:30Again, if you remember from earlier, we have that margin already applied, but applying
02:35it here, I had this little bug that was happening where it was just one pixel off.
02:39So applying the margin inside here as well fix that.
02:42We're changing the display to inline so that the logo and the tagline will display properly,
02:48and then we're giving it a background image. And for that we're going out, grabbing the
02:51desolve ago, and just go ahead and putting it on the left-hand side and vertically centering
02:56it so that it vertically centers with our text.
02:58Now the next selector, the header h2, we're choosing the font-family Cantarell for it as well.
03:03We're italicizing it. We're making sure that it's not bold. We're setting its font-weight to normal.
03:07Its font-size is going to be considerably smaller than the header.
03:11Color still needs to be white.
03:12We're floating it to the left as well, so that again, it can stack.
03:15We're transforming text is lowercase, putting a little bit of letter spacing in there, because
03:19at that size, the text can get a little close together for a tagline you're trying to read.
03:24And again, notice that we're giving it a same line-height of 165, which again is going to
03:27vertically center it within that space. So there is our header.
03:31If I save this and go out to the browser and scroll up and refresh this, you can see that
03:37the big difference here, the logo is on the left-hand side.
03:39We've got enough spacing there for the desolve, and then our tagline is aligning to the right of that.
03:44Okay. So now we're going to focus our efforts on the mission area.
03:47If I go into my code and scroll down below my mission styles, I'll go ahead and paste
03:52those in. And we really only have two selectors there: the mission h1 and the mission p.
03:58So let's tackle the mission h1 first.
04:01The font-size for that is 2.2 ems, and that's a statement about your loving of urban photography as much as we do.
04:07We've got a little bit of padding to the top of 290 pixels, so actually, quite a bit of padding.
04:11What that's going to do is it's going to force that header down to give it enough padding
04:15above it to make it look like it's sitting towards the bottom of that.
04:17And that way I don't have to do any absolute positioning.
04:19I can just sort of push it down using padding.
04:20I'm doing a little bit of letter spacing there as well.
04:23Now the mission p, the paragraph is the actual mission statement itself.
04:26I want you to pay attention to the width here.
04:28What we were doing with the width is we are shortening it so that it's only a small percentage
04:32of that overall width of that region.
04:34We're giving it a little bit of padding on the top, a little bit of padding on the
04:37right and left, but none on the bottom. And the height is 350 pixels, which is the exact
04:41same height as the mission region itself.
04:44We've got normal font-size, color, background color. You'll notice that we're using an rgba
04:49value which is alpha value there.
04:51So it's sort of that blue color, but we're making it semi-translucent, so we're giving
04:54a little bit of background.
04:55Now here we are using absolute positioning, and that's one of the reasons why the mission content element,
05:00if you remember that from our last series of exercises, its position was relative because
05:04I want this to be positioned relative to its container.
05:07So absolute positioning. And instead of doing top-left, we're doing top-right,
05:11so it positions at the top right-hand corner of that paragraph to the top right-hand corner
05:15of the mission content region.
05:16And if I save this and preview it, you can see what happens. We Love Urban Photography,
05:21it goes down to the bottom because of all the padding that it has on here.
05:24And then the mission statement itself positions itself on the right-hand side.
05:28Now, if you're wondering where I got that width from, that width basically mirrors the width
05:33of the column below it--maybe not quite precisely but enough to make it feel right.
05:38So I've got a little bit of padding going on there. And I kept enough space below this.
05:42You may think, well, gosh, you could have increased the line-height to make that a little
05:45bit better, but remember, with a responsive layout that's fluid like this, you have to deal with
05:49the fact that somebody could resize this, or maybe the desktop or the laptop is a little
05:53bit different size there. So I am allowing myself a little bit of space inside that area.
05:58Okay, we are going to finish up by going ahead and doing the interior spacing for these feature article regions.
06:05So I am going to scroll down to my article styles and right after article section, I'm
06:08going to go ahead and paste my article styles. And let's just go through these one at a time.
06:14Again, feel free to pause.
06:15We're starting right here with article h1.
06:17The article h1 is actually the top header, so it's not the individual feature galleries themselves.
06:22It's kind of like, this is the identifier of the space.
06:25So we are using a sprite here.
06:26We are going to talk a little bit more about that in a chapter on navigation, so I won't go
06:30over them in great detail here.
06:31But essentially, what it's doing is it's pulling up sprites, which is a series of icons, and
06:35it's choosing one of those based upon the background positioning.
06:38And we're going to give it enough padding so that the image will display,
06:42so 20 pixels top, 0 for right and left, and then 5 pixels for the bottom.
06:46You'll notice we don't need any padding on right-hand side because it's taking this all
06:49the way to the right-hand side of the heading.
06:51The article h2, we're changing our font to Cardo, which is the second web font we're using.
06:56A fairly large size of 2.8 ems.
06:58We're floating that to the left, and we're giving it a bottom margin of 1 ems.
07:02Now remember, the article h2 is the actual name of the gallery that this in, so in this
07:06case it would be philly for the first one.
07:08The article p is any paragraph inside of that.
07:10So we've got a font-size of 1.2em and a margin top and bottom of .8 ems.
07:14We are being very specific with our pubdate, so article p.pubdate. We're saying for that
07:21we want same font-size 1.2ems, text-transform to uppercase, but we're floating that to the right.
07:26So because we're floating the header to the left and floating the publication date to
07:29the right, they are going to appear right beside each other as if they were on the same line.
07:33We're giving a little bit of padding up top so we can adjust our baselines so that they match
07:36up and then zeroing out the margins so there is no margin collapse below that.
07:41Now for the article preview--I don't know if you remember this, but the preview is that div tag that we created.
07:46I'm giving it a height of 250 pixels, then I'm clearing both of them so that the floating
07:51that was going on between the header and the pubdate are now wiped out.
07:54If I save this, go back in my browser, and preview that,
07:58you can see, there is the icon that we brought in for the h1.
08:01Here is the h2, much larger in size.
08:04It's floating to the left, publication date is floating to the right.
08:07We have the space here for our image. You'll notice that it is clickable because the link
08:11inside of it is set to block so it's expanding throughout the whole thing.
08:14And then we have the caption being formatted by just the regular paragraph text, Join us
08:18as we visit the city of brotherly love.
08:20What we didn't place inside any of these-- you can see the styling just repeats because
08:24the structure is the same--what we didn't place inside of them is the images.
08:27So that's the last thing we have to do.
08:29I am going to go back into my code, and just below that I am going to go ahead and paste
08:33in all of my individual images.
08:34Let me scroll up so we can see those. We only have three of them.
08:38And what we're doing is we're using the classes that are applied to these sections--
08:42so philly, chicago and nyc--and then targeting the actual div tag with class of preview.
08:48We are using three different backgrounds.
08:50You can see we are just pulling them from the _images directory.
08:52We are finding the Philly banner, the Chicago banner, the New York City banner, and we're
08:56just telling it not to repeat, so we're telling it to fill that space. And it's just getting
08:59the default positioning, which is top-left.
09:01So if I save that, go back in, and refresh, now you can see the images coming in as well.
09:07Now, another thing that I want to point out about background images that I think is
09:10really neat in terms of responsive designs:
09:13if the container that they are inside is designed to flex, then basically you're going to show
09:18and hide part of that image.
09:20You'll notice that here, for example, that at a wider screen, I am showing much more of
09:23the image; at a smaller screen I am showing less of it, until it sort of locks into place.
09:28One of the things that you really want to think about if you are going to use this technique:
09:32is a very important part of the photograph or image is going to trimmed off, and in
09:35terms of which way it's going to expand, do I need to make sure that the photographs have
09:40their point of interest on the other side or close to it, that sort of thing?
09:44So if you're going to use this technique-- it's almost like a sliding door technique.
09:47I really like it, but it's one of the things that you're going to have to consider, in terms
09:51of what part of that photograph is going to be trimmed off, and is that okay. All right!
09:55Our layout, looking a lot better now that we've refined those three areas. The desktop layout
09:59is really coming into focus here.
10:01There are certain things like the navigation that isn't done yet, some of the other regions,
10:05but for the most part we're in good shape.
10:08So now, here, we're taking advantage of those media queries, and in doing that we're able
10:12to concentrate on refining the styling for a single range of our target sizes.
10:16So next up, we're going to see how to translate our design to a smaller screen in terms of
10:20the tablet and still keep our design philosophy intact.
Collapse this transcript
Refining tablet layouts
00:00After styling our desktop regions, we have an established look and feel for our site.
00:04As screen sizes get smaller, we need to try to retain that look and feel while optimizing
00:09the layout for less screen real estate.
00:11Let's go ahead and explore that concept as we refine our tablet layout, and for continuity's
00:15sake, we'll focus on the exact same three page regions.
00:19So I have the index.htm file open from 02_09 folder, and right know I am focusing on the
00:25main.css file, which is found in the _css directory as well.
00:28I've jumped down to the tablet styles, which you can find at about line 489 or so.
00:34Previewing the index page in the browser--let me just switch over to that.
00:39You can see again, those areas really aren't that fleshed out.
00:42There is a little bit of styling going on in the top region.
00:44We've got the size of it and the color, but the typography and the logo are all wrong.
00:49The mission statement area is sort of a mess, and we really just have the bare bones of
00:53the structure of those detailed regions.
00:55So let's go ahead and focus on bringing over some styling into our tablet region that has
01:01the same look and feel as our desktop, but is more designed for the space that we have available to us.
01:05Okay, so again, I am going to start in the header styles.
01:08So right after the header selector, I am going to go ahead and add my first bit of code.
01:13Now, for this one, again we're doing the same thing where I am just going to paste some
01:17code in and over the lines rather than have you watch me type all this out.
01:20The first selector targets the header h1, which is the company name.
01:24You'll notice again font-size is pretty large, about the same size as before.
01:28Same line-height, same width, for the most part, same image.
01:32So really nothing has changed there.
01:34What has changed, however, is the h2, which if you remember, is the tag line.
01:39It's not critically important that that tagline display.
01:42When we have enough room on the desktop it's kind of nice to see it, but it's not going
01:46to make or break our site.
01:47And we run out of room at that size.
01:49I'd rather not shrink the logo down.
01:50I'd rather not shrink the header down, because the company branding is so strong with that.
01:55So in this case, I've made the decision to go ahead and turn that header off h2 display: none.
01:59Now there is something that you need to understand about display: none, in terms of using it
02:04for responsive design.
02:06If somebody is viewing this on a screen reader or other accessibility-enabled device, display:
02:11none basically hides that content from those devices.
02:15So there are other ways that you could do this.
02:18You could use the visibility property.
02:20You could use absolute positioning to move it off the screen.
02:23So if you need to keep it accessible, there are ways to do that.
02:25This is certainly not it.
02:26My thinking here goes that if this is on a tablet or other type of device, chances are
02:31they probably won't be using a screen reader.
02:33However, if they are, if the tagline isn't read, again it's not critical.
02:38It's not crucial content, so in that sense it's not that big of a deal if it doesn't get read as well.
02:44Next up, I am going to tackle the mission area.
02:46By the way, if I save this and preview--let's go ahead and refresh--and you can see, the logo comes in.
02:53This version of it is centered within the browser, and our tagline goes away.
02:57All right, so if I go back in and go down to the mission area, just below the existing
03:02mission select, I am going to go ahead and add a couple of more.
03:04I start off with mission h1, so that would be the text we love urban photography.
03:11Font-weight is bold.
03:11Font-size is 120%, so it's relative font-size and relative to the region that it's inside of.
03:17That's going to help scale it to the area, the screen real estate we have available to
03:21us, but still make it a little bit larger than the default font-size for that region.
03:26We're making it white, adding a little bit of letter spacing to it, and this time we're
03:29aligning it to the center.
03:30And notice for the margin-top it's only 1em.
03:32If you remember for desktop, we have a really big padding on top that sort of pushed it
03:36down to the bottom of that region.
03:38In this case, we don't really want it to occupy the bottom; we want it towards the top.
03:42So we're only having a margin-top of 1em, which is going to hold it off the top of that image.
03:46Now, why is it that we don't want it to go all the way down?
03:49Well, if you remember on the desktop, the paragraph was sort of aligned all the way
03:53over on the right-hand side of the mission statement, almost to sort of fill up that
03:56second column, if you will.
03:58Now this is a one-column layout, so in this case you'll notice that for the mission paragraph
04:03selector, which is underneath that .mission p, the width is at 80%, the margin is at 0 and auto.
04:09That's going to center it within, that and then the margin-top is 220px (pixels), so
04:12that is going to push it down.
04:14So in this case the paragraph is going to be at the bottom of the image, whereas the
04:18h1 itself is going to be up towards the top.
04:20So if we save this, go back in the browser, and refresh, we can see that that really helps
04:26our mission statement area.
04:27And this time, instead of putting the paragraph on top of the image, as we did in the last
04:32one, when we're actually pushing it down below it a little bit, so we get this uninterrupted
04:35view of the city, because we don't have quite as much screen real estate.
04:39And then the paragraph text is written underneath it in a very legible fashion.
04:43And we have enough of margin on either side of it to really keep it tight, compact, and
04:47readable, so it sort of fits in with the design the way it is.
04:51All right, so next I want to focus on our region down here where we have those individual
04:56featured galleries.
04:56So I am going to go back into my styles, scroll down to my article styles, and just underneath
05:01article section I am going to add a few more selectors.
05:05So here, if I scroll back up into all of these, we're going to start with this one, the article h1.
05:10Again, remember, that is the actual heading for all of the featured galleries.
05:16Here we are using the same icon sprite that we used before.
05:20We're aligning it to the right top as well, and we're giving it a little bit more padding,
05:24but in terms of size, we're not really increasing the size or changing it at all.
05:27So for the most part, it's going to look very similar to what we had in the desktop version of it.
05:31We see dramatic changes when we start going down into the featured galleries themselves.
05:36So the article h2, we have a 2.4em size on that, so it's still a little bit larger than
05:42the heading above it.
05:43Now it's Cardo, so again, we're going back to the web font that we're using for those.
05:48And this one notice that this is floating to the left, so we've got left float on this.
05:52If you remember in the mockup what we want is we want all the text on the left-hand side
05:56and we want the image on the right-hand side.
05:58And notice that we're doing a clear to left so that the rest of the content doesn't stack beside it.
06:04We're giving it a margin-bottom of 0, which is taking off some of the default margin,
06:07and then we give it a width of 40%, and that width is very important so that we have enough
06:11room for the image.
06:12You'll notice very similar styling when we go down to the generic paragraph selector for our articles.
06:17Font-size of 1em, a margin of 0, and notice we're also doing a float: left and clear:
06:21left on that, and we're giving it the same width of 40%.
06:24Now just as before, we want to add some specific styling to the publishing date.
06:28We'll transform the text to uppercase and then we're applying a slightly different margin
06:32on that; we're just applying a 4em margin to the bottom, which is going to give us a
06:36lot of space between the heading, the publication date, and then the caption to the bottom of that.
06:42It's width is 40% as well.
06:43Now, the article preview is going to handle the image itself.
06:47Notice that we're giving it a fixed height of 175 pixels, which when we start placing
06:52the background graphics in there, it's going to be the height of those.
06:54We're absolutely positioning in it, which is one of the reasons why the earlier parent
06:58container had a relative position applied to it.
07:01We're aligning it to the top right, and then we're giving it a width of 55%.
07:04Now remember, this is actually the background image that is going to go into these.
07:08It's actually a little bit larger than the container.
07:10So that width of 55%, as we flex that layout, we're going to have the same effect that we
07:15had in the desktop, which is, parts of the image will be revealed and part it will be
07:18sort of hidden, but the ratio between content and image will remain the same: 40% for the
07:23content, 55% for the image.
07:25So if I save this and go back into my browser and refresh this, you can see sort of what's happening here.
07:31The heading and the publication date are stacking on top of each other and then we have this
07:35little bit of space between the caption and then we have this space right over here for the image.
07:39Again, remember, that has a link applied to it, and the link has black formatting applied
07:43to it, so this whole area is going to be clickable as well as this heading.
07:47All right, so the last thing we need to do is go back in and handle which images are
07:51going to go into which of the featured galleries.
07:54So just below the code that we just worked on, I am going to go ahead and paste our last
07:57bit of selectors for the tablet styles.
08:01And there I'm looking at, again, using the class selector Philly, Chicago, and NYC to
08:06target the specific previews and put the images inside of them.
08:09Now, I do want to point out again, for the images that are in here, they're not the same images.
08:14Notice that these are still philly_banner, chicago_banner, nyc_banner, but they are the
08:18small version of this.
08:19So, this allows me to make some editorial decisions, if you will, as well.
08:23Let's say you have an image and you just want to shrink that image down for a smaller size.
08:27Now a lot of times you lose a lot of that detail as you shrink the image down.
08:29So, instead of just shrinking the image down, you can simply crop it so that the image that
08:34you're focused on remains the same size, but the image itself is smaller.
08:38So a lot of times you can make those editorial decisions using this technique as well that
08:41you can't get with just an image that's going to scale up and down.
08:45All right, so as I save this and go back into my browser and refresh the page, the images will come.
08:51Once again, you can see, they're the smaller versions of them.
08:54They don't really look smaller, and that's because they've been cropped to a new size,
08:58with a little less data.
09:00If I resize the browser window, notice that when I start going down to the tablet layout,
09:04again there is some flex there, so I'm cutting off a portion of the image.
09:09So I have to really think very carefully about how I crop those images and which side of
09:14those images is going to be hidden, and that sort of allows me to determine where to crop
09:19it, where the focal point, where that point of interest is going to be for those.
09:22Now, as you look through the rest of the styles, focus on what's being done to present the
09:27content in a similar design style from one layout to the other, while still taking advantage
09:32of this available space, like we did here.
09:34We were able to stack the content instead of stack it on top of each other, and we still
09:38have a nice image preview regardless of the fact that we have smaller image size.
09:42Now, in other instances, you're going to find this workflow is going to force you to make
09:46some pretty tough design decisions, you know while in other cases you're going to find
09:51that that additional focus actually helps you refine the design in ways that you probably
09:56wouldn't even have considered otherwise.
Collapse this transcript
Refining mobile layouts
00:00We'll finish out our chapter on layout by refining our mobile layout.
00:04And as before, we are going to focus on those three core areas: the header, mission statement,
00:09and featured galleries sections.
00:10So I am working on the index file. This time from the 02_10 directory, I am also working
00:15on the main.css, which can be found in the _css directory as well.
00:19Just to kind of show you where we are in terms of the mobile layout, I am going to open that
00:22up in the browser. You can see, again, we have got some basic styling going on. We have got a
00:26little bit of the structure happening, and that's really all being done right now by
00:30our global styles. And some of the basic layout styling is being done by the container styling
00:35that we did a little bit earlier.
00:37So let's jump back into our mobile styles, which you can find at around line 436.
00:42Again, we are going to focus on each of the sections individually, and we'll start, as we
00:47have before, with the header styles. So let me go ahead and add the code that we are going to be using there.
00:53So, we start off with the header h1, nothing new there. And remember, this is the company name and the logo.
01:00Font-size is going to be a little bit small here; of course we are dealing with mobile
01:02screen sizes so everything is going to shrink just a tad bit.
01:05We have enough padding on the left-hand side to deal with our logo.
01:09We have a line-height of 70px (pixels), so a little bit smaller. And if you remember, the
01:12height of the header is also 70px (pixels) so that's going to vertically center it.
01:15And we have a width of 190 pixels, and then we are going to centering it using the auto margin technique.
01:20Now, I do want you to notice that we are using a slightly different version of the desolve_logo
01:23here. We are using 50 pixel by 50 pixel version of the PNG file, so that's going to shrink down as well.
01:30And just as we did on the tablet layout, we are going ahead and turning the display of
01:34the tagline off by using display: none.
01:37So if I save this, go back in the browser, and refresh, you can see it's hiding the
01:42Fine Urban Photography, and we now have the logo and the branding front and center, right
01:47there in the middle of that header area.
01:49So again, with smaller screen real estate on mobile devices, or any smaller screens,
01:54it's a really good idea to get to the content as quickly as you can.
01:57Now we haven't tackled navigation yet, but we are going to skip over that and we are
02:00going to go straight to the mission statement.
02:02I am going to go down to our mission styles, and then right after the generic sort of mission
02:07container, I am going to go ahead and put in two more selectors.
02:11This one, again, is going to tackle the mission h1 and mission p.
02:13Now remember, in the desktop and the tablet versions of this, we have that sort of skyline banner graphic.
02:20That's this nice visual that's up there.
02:21A lot of times when you start moving towards these smaller screens or the mobile devices,
02:26you have to let some of that branding or some of that visual impact go.
02:30You know, people are going to be a little bit more interested in the content and not as
02:33much interested in scrolling through these really nice sort of visually resting images.
02:39Now, not every site is that way, but for the most part, you want to present the content
02:42as quickly as possible.
02:43So what I am doing here is I am taking away the image for the mission h1, the header where
02:49we have got some font of bold, we have got font size of 1em, so we are shrinking it a
02:54little bit. We are aligning the text to the center, and then we are just giving it a half
02:57of an em margin to keep it in the paragraph away from each other, so they are going to
03:01be fairly tight in terms of their spacing.
03:03If we go down the paragraph, I am changing the width to 90%, which is going to give us
03:065% margins on either side.
03:09The font size is a little bit smaller than the heading 1, at 0.5ems. Again we are auto-centering
03:14it as well, and we are giving it a line-height of 2 to give it a little bit of visual spacing
03:18so it's a little bit easier to read.
03:20If I save that and preview it, you can see the change that happens to WE LOVE URBAN PHOTOGRAPHY.
03:26We have a heading in our paragraph and it's really just content at this point.
03:29You know we'll get the mission statement, and people that come to visit the website can
03:32get a very quick and easy introduction into what the site is all about and what content
03:37is available on the site.
03:38If I go back into our styles, it's time to start looking at those article regions with
03:43the repeating featured articles.
03:44So I am going to paste the code for our specific article regions inside there, and we are going to start
03:49again with this article h1.
03:52Now for this one, again, we are using those icon sprites. This time we are using the 50.png icon sprites.
03:58Notice that we have a little bit of padding at the top, none to the right and left, a
04:00little bit of padding on the bottom, and the icon is going to the right-top so it's aligning
04:05to the right side, as it has before.
04:07So that's consistent, really, almost all the way down.
04:09Now, when we go into the featured gallery areas with the article h2, again we can see that
04:13we are using the Cardo font, so we are keeping that consistent.
04:16The font-size is 2em, so, much like our other designs, the desktop and tablet layouts, that
04:21heading is going to be a good bit larger than the text around it, drawing attention and focus to it.
04:26We have a margin-bottom of 0.
04:28Now remember, we are going back here to a single-column layout where this content is going
04:33to be stacked one on top of each other.
04:35Now, there's something a little different here than we had in the tablet styles and the desktop
04:40styles, and that's that the paragraph that has the caption applied to it is going to
04:44be styled individually.
04:45Notice that the font-size for that is a good bit smaller, .85ems, and the margin-top on
04:49that is 1em, to hold it away from the image that's going to be below that.
04:54Now the articles publishing date, that paragraph, notice that that is sized at 1em. The text
04:59transform is set to uppercase, and the margin-bottom on that is 1em as well.
05:04Now, for the article preview--and that's where the image goes, the only styling we did on
05:08that is to give it a height of 175 pixels, and that's really just sort of holding the
05:11area for that image when we placed the image inside that.
05:14If I save this, go back to our layout, and refresh, as I scroll down, you can see the
05:18icon comes in, and now we have an enough space, we are just sort of stacking these elements.
05:23The publishing date is just below the headline, we have space for our image, and then we have
05:27the caption just below that.
05:28All right, so the last thing we need to do is place the images inside there. And so just
05:32below the article preview, I am going to go ahead and paste that code. And it's exactly
05:36the same thing that we were using for the tablets. We are using the smaller version of those banners.
05:41So they were designed with the tablet and the mobile screen in mind, so you are not generating
05:45a ton of assets; you can sort of reuse them.
05:48And again, even though the physical area is going to be smaller, because the images were
05:52cropped a specific way, you're still going to get a nice preview of that particular gallery.
05:56So if I save this and go back in and refresh that, you can see those images come in.
06:02And because this is indeed a flexible layout, as I begin to resize this, you can see more
06:09or less of the image is shown, and then it'll break and go into the tablet layout.
06:13So for some of the newer phones, or if the phone is in landscape mode instead of portrait,
06:18they are still going to see a good bit of that image preview because we have this flexible
06:22layout within a specific screen size range.
06:25Now, obviously, for what we've been doing here for the past couple of layouts, we are really
06:29just focusing on those three page regions for our various layouts.
06:33So we have our desktop, we have our tablet, and then we have the mobile one.
06:39But you know one of things that I hope is fairly obvious at this point is that it really
06:43takes a fair amount of focus on your part to make sure that you're maintaining a consistent
06:49styling across all these multiple layouts, while still sort of really taking
06:53advantage of that available screen size.
06:55So you are sort of designing for three different contexts and you want it to be consistent across those.
07:01Now make sure that as you begin to plan any of the responsive designs that you work on,
07:05that you really give yourself enough time to plan how you're going to approach this
07:10particular styling challenge, because it's not as easy as it looks.
07:13It can sometimes be really, really challenging. You can fall in love with something in a
07:17desktop size and then when it gets down to a mobile size, you have sort of lost all the
07:21things that made it good.
07:23Same thing: you can start on a mobile size, sort of scale up and start adding things, and
07:27realize that the minimalist style you had at the mobile really isn't working at the desktop.
07:32So, be sure to try to achieve the styling in the most efficient way possible.
07:37If you find that achieving your desired styling results in a lot of code bloat, it might be
07:42time to go back and assess your overall layout strategy and find something that's slightly more efficient.
07:48
Collapse this transcript
3. Responsive Navigation
Defining a responsive navigation strategy
00:00One of the most critical elements of any responsive design is its navigation.
00:04Without a solid strategy for defining how navigation should function across devices
00:08and screen sizes, your project will likely not succeed, no matter how well designed the
00:13rest of the site is.
00:15In this chapter we're going to be building two responsive menus.
00:19The first one, and you see it here, is relatively simple, and it simply requires that we carefully
00:25style it across different screen sizes. You can see here, at the desktop size, we have a lot
00:29going on. We have icons, we have some additional text. But as we'd resize the screen, when
00:33we get down to tablet size, we're resizing the icons, we're placing them on a different
00:36location, and then when we get down to mobile devices, we're doing pretty much of the same
00:40thing, resizing the icons and just placing them in different places.
00:44Notice also we're hiding that sort of extra that sort of caption text there.
00:48Now the second menu is going to be a little bit more challenging.
00:52At desktop size, it's just simply a normal HTML and CSS dropdown menu. Nothing really fancy
00:57going on about this.
00:58But as we resize this, when we get down towards tablet styling, you can see that we still
01:03have a hover dropdown menu, because so many of the devices at that size support mouses and pointers.
01:10But a lot of devices of that size are also tablets, so we have to also account for the
01:15fact that this could be a touchscreen device, so we need to enable this menu for touchscreen use as well.
01:20When we go down to mobile space, we hide not only the submenus but the menu itself.
01:25This way it saves a lot of screen real estate and allows mobile users to get right into
01:29the content and then expand the menu if they want to see that.
01:32It also gives them the ability to toggle the menu on and off.
01:36Now, in both of these cases, we're going to look at not only the techniques that are required
01:40to create these, but we're also going to explore and take a look at those variables and constraints
01:45that you need to consider while building these responsive navigations as well.
01:49Now, since navigation can change so dramatically from one project to the next, it's really
01:55just critically important that you stop and take the time to think through how a site's
01:59navigation should work at different screen sizes and on devices with different functionality.
02:04That's really, really important.
02:06We'll need to really carefully plan around what's best for a specific context and then
02:11consider what your users' expectations are, depending upon the device that they're using,
02:15to access your content, and a lot of people lose sight of that.
02:18And although I usually save additional resources to the end of a course, for this particular
02:23chapter I wanted to start off by giving you a couple of online resources that can help
02:27you dig a little deeper into responsive navigation and explore some of the patterns that are
02:32common to responsive design.
02:34First, I highly recommend checking out Brad Frost's post on responsive navigation patterns,
02:39where he lists the pros and cons of some of the common responsive approaches. And I want
02:44to take a look at just a couple of these.
02:45This first one is this Top Nav Or "Do Nothing" Approach.
02:48That simply is just sort of a horizontal list of links that is designed to break down to
02:53new lines when screen sizes changed, and that just sort of allows the navigation of
02:57flex, but it's not always the most attractive approach.
02:59Now one that I'm really interested in is The Footer Anchor approach, and I am just going
03:03to skip down to this one.
03:05The Footer Anchor approach is the idea that you're going to place the navigation at the
03:08very bottom of the page now, in the footer itself, and not at the top, which has been a
03:12common pattern for years on the web.
03:14Now, this does two things.
03:16Number one, for the mobile user, it frees up the top of the page for the content, and they
03:20can reach the navigation when they get through scrolling all the way down to the bottom.
03:24For desktop users, this is kind of interesting as well.
03:27It allows designers to respond to the recent trend in laptops becoming touch devices, because
03:32if someone is typing on a laptop, studies have shown that they really just sort of like
03:36to reach up towards the bottom of the screen and not have to go all the way up to the top to hit the navigation.
03:41So this is a pattern you keep your eye on.
03:43I think it's going to increase in popularity as we see more of those devices on the market.
03:47Also, he talks about things like converting navigations to toggles, so select menus, and
03:54he also covers this one, The Left Nav Flyout. This is the one that you'll probably see on
03:57Facebook a lot where the navigation is sort of off to the left-hand side and you can swipe
04:02or hit a button to have it animate on when you need it.
04:04It just kind of hides it out of the way and whenever you need it, it sort of brings it in.
04:08This is actually a variation on what's called the off-canvas approach, and Luke Wroblewski
04:14wrote a really nice post about that earlier in 2012 about off-canvas multi-device layouts.
04:20It's not just for navigation, but certainly people are using it for that.
04:25Now, this was actually followed up by Jason Weaver, who put a nice online demo of these
04:30off-canvas patterns online. And you can kind of see what's going on with this layout.
04:34You have three columns and as you resize the page and screen real estate shrinks, the columns
04:41will start disappearing, first the right- hand column because it's less important, and then
04:45finally the left-hand column.
04:47But once you get down to this size, you can bring those columns back by simply animating
04:51them onto the screen. So this is very handy on a phone and you could even wire that up
04:55to responds to swipe navigation or things like that.
04:58Now, I also want to mention Brad's follow-up post on complex navigation patterns for responsive design.
05:04It really just sort of takes what he was doing earlier and extends into some more complex
05:08patterns, so this is also worthy reading.
05:10Now, as you look through all of the different approaches that I've shown you here, I want
05:14you to focus on the fact that there isn't a single one of these that can claim to be
05:18the absolute best way to approach planning navigation for responsive sites.
05:23Now, the unique nature of the site navigation when you're changing devices and screen sizes
05:28makes it really challenging the plan for when you're building your responsive site.
05:32So my advice to you is to familiarize yourself with as many options and techniques as possible,
05:38and don't be afraid to come up with your own unique solutions if the project requires it.
Collapse this transcript
Structuring basic menus
00:00If your site features minimal navigation, making the navigation function across all
00:04screen sizes is a fairly straightforward operation.
00:08Take the finished desolve.org basic menu that you're seeing here, for example.
00:13Now, this menu only features four links, so it's fairly easy to make sure that all menu
00:17items are being displayed effectively across all of the different screen sizes that we're targeting.
00:22However, even simple menus like this one can still have complex requirements.
00:27Now, notice that at the desktop, or larger screen size you're seeing here, our nice helpful
00:31tagline appears under each of the menu items.
00:34However, as we begin to lose space, we start losing the amount of space that's necessary to
00:39show those taglines.
00:40So, we kind of have to figure out a way to hide those taglines, and do we need to have
00:44enough space for icons as well?
00:47As we get down to even less space within the mobile environment, we need to start thinking
00:50about things like target areas for touch events and making sure that there's enough space
00:55there for people to accurately select the different menu items.
00:59This means that really, no matter how simple the menu is that you're working on, you still
01:03have to consider how it's going to change as you plan its initial structure, and that's
01:07where we're going to start with building this basic menu with its initial HTML structure.
01:12So, I'm going to switch over to my code editor, and I'm working on the index.htm page, which
01:17you can find in 03_02 directory.
01:20Now, if I scroll down just a little bit in the HTML here, I can see, on about line 23,
01:26I have an HTML comment that says, "nav goes here." Fair enough.
01:29So I am going to go and delete that comment, don't need that anymore, and I'm going to start
01:33off by making sure that I have a nice solidly structured semantic menu.
01:38So I'm going to use the HTML5 nav element to help me do that.
01:42So, I'm going to say nav id="mainNav" and then I'm going to give it a role of navigation.
01:48And again, I just want this to be as accessible as possible and structured properly, so I've
01:53got a nav element that's going to hold our navigation.
01:56Now inside that, I'm initially going to go ahead and put an h2, and the h2 for this is
02:00going to be site navigation.
02:02Now, this might draw some head scratching.
02:04You might be going, why in the world are you doing that?
02:07Well, for me, this is all about the HTML5 outlining algorithm and making sure that I'm
02:11passing enough information about exactly what this is.
02:15Essentially, the HTML5 outline algorithm says that any new section in a nav that's sectioning content
02:21will be represented in an outline by its initial heading.
02:24If it doesn't have one, it then becomes an untitled segment.
02:27I just want to show you that kind of in action, so you can see why I'm doing this.
02:31If I scroll down to the aside that we have down here, you can see that the aside has
02:37a role of complementary, but there's no heading directly after that.
02:40So, there is absolutely nothing to identify what that aside is.
02:43Now, if I switch back to the finished version of this, I'm going to use a neat little extension
02:48that comes with Chrome that you can go out and get called the HTML5 Outliner.
02:51If I go over to the HTML5 Outliner and click on my menu, you can see that I get an outline
02:57here, and I can actually jump to those areas.
03:00This is a really neat use of the HTML5 outline algorithm, and I can see future uses
03:05of being a nice way to sort of quickly skim through and look at a TOC for a page.
03:10But you can see right here, site navigation, that's because of our heading.
03:13However, that aside that I showed you earlier, see how it's untitled? And so when people
03:18sort of parse content and do things like this with it, you might have a lot of those
03:21sort of untitleds coming up.
03:23So, it's not absolute necessary that we do this.
03:26This is more optional, but it's something that I kind of like to do in all my sections
03:29to make sure that they have a title.
03:31Now, that also means that later on in our styles, we're going to have to figure out a way to
03:34hide that, because we don't want that to come through visually.
03:37So after that, we're going to do what a countless people have done before us, and we're going
03:41to create an unordered list.
03:43This unordered list is going to hold all of our menu.
03:46It's a really good idea to organize all of your menus with lists, simply because it's
03:50a very logical way to group these links.
03:54Inside the unordered list, I'm going to do my first list item, and inside the list item,
03:57I'm just going to go ahead and do a link.
03:59So, I'm going to do a href, and for the first one, it's going to go to galleries.htm, and
04:06then after that, I'm going to give it a title, and this one is going to be Our photo galleries.
04:12I'm going to go ahead and also identify each one of these with a class, and this one is
04:16going to be gallery.
04:17Not only does that give me a little more semantic meaning for this link, but it also gives me a
04:21styling hook for later icons.
04:23I'm also going to go ahead and identify this one as being the current link, with the word current.
04:27Now, it's not the current page, but later on when we start doing our styling, I'm going
04:31to show you how to deal with current styles.
04:33So, you would anticipate that being injected dynamically based on the page you are on.
04:37Now, inside this anchor, I'm going to go ahead and type in the text Galleries, and then just
04:42after that, I'm going to add our tagline text.
04:44I'm just going to surround this with an em tag, and I'm just going to say, explore our
04:49photos. So the link would actually read galleries explore our photos, which is fine. That reads
04:54just fine and it is a little bit more descriptive, and the emphasis tag gives us a styling hook
04:59later on, when we want to style this.
05:02So, I'm going to close out all of my tags here: my emphasis, my anchor, and my list item tag.
05:07Now, I'm a huge believer in saving yourself some time, so I'm going to go ahead and copy
05:11this for our next one, making sure that I copy both the opening and the closing list
05:15item tag and paste that down.
05:17And then I'm just going to change the various elements.
05:20The href will link to gear.htm for our second link.
05:24The title for this one is going to be Favorite gear, and the class for this is going to be a
05:29single class, and that's just going to be gear.
05:33The text inside the link is going to read Gear for just the main text and then inside
05:37the em tag, I'm going to type in our favorite equipment.
05:43I'm going to keep going, paste the third link. Inside that I'm going to do contact.htm.
05:51The title for this one is going to be Get in touch, class, and you could probably already
05:58guess what this is going to be.
05:59It's going to be Interact. I fooled you; it's not going to be contact.
06:04And then the text inside of it is going to interact.
06:08Now, inside the em tag, our text is going to read contact, follow, or submit your own.
06:19So, it's very descriptive of what people can do on the contact page.
06:23They can contact us.
06:24They can follow us through social media, or they can submit their own galleries.
06:28We have one more link to go.
06:30This is going to go to the shop.htm, and our title is going to be kind of pushy, Buy our
06:37stuff. The class for that is going to shop.
06:41And the main link text will also be Shop.
06:43Now notice that I'm capitalizing these. It doesn't really matter, and we're going to be using
06:46CSS later on to control that anyway.
06:49And then inside the emphasis, it's going to be, buy our stuff,
06:53exclamation mark because we are really excited about it.
06:55Okay, so we're going to go ahead and save that, and now we have our basic menu in place.
07:00All that's left now is that we need to style it across multiple screen layouts, and we'll
07:04tackle that in our next series of exercises.
Collapse this transcript
Styling basic menus
00:00When you're styling navigation across multiple screen sizes, you also have to consider functionality.
00:06At smaller sizes of the screens are likely to be touch, and since your hover styles
00:10are won't to be working in a touchscreen, you really need to think about how effective
00:14your styles are going to be when indicating active menu items.
00:18You also need to consider the clickable area required on touch devices as well, to avoid
00:22frustrating your users.
00:24So let's take a look at styling our navigation across three different types of screen sizes:
00:28our desktop, tablet, and mobile layouts.
00:31Now I have the index.htm file open from the 03_03 folder. We're also going to be working
00:36mainly, honestly, in the main.css file, which is found in the _css directory of the same folder.
00:43As we we're doing in the previous chapter, I'm going to be pasting some code in so that,
00:47number one, it's going to save us some time, and it's going to save you from the torture
00:51of having to watch me type, because we got a good bit of CSS that we're going to be writing here.
00:54I'm going to go over the selectors and talk about what they're doing for us, so when we
00:58get to the point where I'm doing a block of it, fill free to just sort of pause the movie
01:01at that point and then enter in the selectors.
01:04So the first thing I want to do is I'm going to scroll down to my global styles, so we're
01:07going to handle our global navigation styles first. Probably about line I don't know 184
01:12or so I think it was, yeah,
01:14you want to find the area right between the header styles and mission styles.
01:17So I'm just going to place my cursor in there. Let me go ahead and put the styles that
01:21we're going to be doing, and then I'm going to scroll back up and go over these. And you
01:25can pause the video and kind of look at these, and I'll scroll back down so that you can get all of them.
01:30So the first section of styles here, first I started off with a comment, because I like
01:34to identify all the different regions.
01:36The first thing is the mainNav, which is of course, I'm using the ID attribute of the nav
01:41element to identify just that particular nav. I'm setting overflow to hidden.
01:45The thing here that really matters is the margin bottom on this, which is 1.5ems.
01:50It's giving us enough space below it for the mission statement that we have that follows
01:53it. And then I'm going ahead and floating all of our list items, so by default this menu
01:58is going to appear as a horizontal list of links.
02:01Now, the reason I'm doing this in the global navigation styles is so that if media queries
02:05fail for whatever reason, we do have a menu that we'll still flex with the screen space,
02:11and the list items will just stack as high as they need to based on the screen size.
02:15If there is enough screen size, they'll display as just an entirely horizontal list and if
02:18not, they'll just sort of stack on top of each other, so it will still be usable.
02:22For the anchor elements inside the #mainNav, we are transforming all the text to uppercase,
02:28we're going to display the links as blocked, and what that's going to do is it's going
02:31to increase the clickable area for that link to the entire area of the list item, which
02:35is good, especially for touch devices. e are setting a color on them and we're turning
02:40the border off, so if I have got any borders applied to links elsewhere in the styles, this
02:45is going to go ahead and strip those out.
02:46I am applying some default hover styling as just changing the color of that, and then for
02:51the current link indicator, you may remember that when we're structuring the menu I changed
02:56its color as well and set the cursor to default, so the pointer cursor doesn't show up. It somebody
03:01is mousing over it, it looks like a dead link even though it's not.
03:04So it's just fooling people a little bit there.
03:06So I'm going to go ahead and save this, and those are our global styles, meaning that's sort
03:10of the baseline or default styling, if you will, for our menu.
03:13Now we need to get into these specifics of each area.
03:16I'm going to start at the very bottom of our styles with the desktop styles, so I'm going
03:19to scroll down. And this is going be around line 1064 or so.
03:25Once again, we are going to be placing this code in between the last of the header styles
03:30and the top of the mission styles.
03:31So I'm just going to create myself a little bit of space here for my nav styles, and I'm
03:36going to go ahead and enter those.
03:38Okay, again, I'm going to scroll up and go over these a little bit.
03:41Now remember, this is for our desktop, desktop-specific styles.
03:45Again, I'm indicating that they are nav styles by this comment.
03:48Now the first thing that I'm doing is for that mainNav element, I'm giving it a padding
03:52left of 3.9%. If you're going to remember back to the last when we're doing layout, that
03:573.9% is sort of the gutter that we're using, or the margins that we're using, on either
04:02side. So that padding left is echoing that and gives us you know consist spacing all the
04:05way down through our layout.
04:07The next thing we're doing is for our list items, the individual items themselves, we
04:11are spacing them apart by using a right margin on them.
04:14So they're floating to the left and then we are pushing them apart from each other with a right margin.
04:19The links themselves, we're just changing the font size, we're aligning the text to the
04:22center, and then we're adding a little bit of padding to the left of 15 pixels.
04:26If you remember from the finished version of this, there are going to be icons that go
04:30with each one of this links, and that padding to left of 15 pixels is giving us enough space for that icon.
04:36The next thing that we need to style at the desktop level is the text that comes inside
04:40the emphasis, or the em, tag.
04:42Notice that we have color, we have a different color set for that that's sort of that darker gray color.
04:47And then we'll also lowering the font size down a little bit, changing the display to
04:51block so that it will actually appear on its own line--it will break down on to it's
04:54own line below the normal linked text--and then we're doing a text transform to lowercase.
04:59So, it's going to look slightly different then our main text. It's going to be smaller,
05:02all lowercase, and then it'll appear directly beneath it. Because all of our link text is
05:06being centered, it'll go ahead and horizontally center those links to each other.
05:11All right, so those are our desktop styles. We're going to save that.
05:14So at this point I'm going to go ahead and preview this in the browser. And you can kind
05:17of see how this is working with our desktop styles. Now our icons are not there yet, but there's
05:22our normal link color and the hover color that we have established. You can see that
05:26the text stacking one of the top to each other, with the emphasis text and the differences in formatting.
05:30All right, so now I need to go up and concentrate on our tablet styles.
05:35Now, the tablet styles are about line--
05:37I don't know--728 or so, somewhere around in that range. So let me scroll up and find
05:42those, and I'll show exactly where they are.
05:44There is our mission styles.
05:46Okay, so, yeah around 729, actually.
05:48So just underneath the, again, header styles and just above the mission styles, I am going
05:52to create a little bit of a space for myself, and then I'm going to go ahead and put in my tablet styles.
05:58All right, so I'm going to go back up to about 730, which is where I pasted them in, and let's
06:02talk about each one of this selectors.
06:04Again, I'm identifying it with the comment. And then for our mainNav, I'm doing something
06:08a little bit different here.
06:10I'm giving it a width of 450 pixels and then I'm using the auto margins centering technique.
06:15Now, the reason that I have a defined width is I know how many link elements that I have.
06:21I'm not going to add any more to them, so I'm not worried about later on, dynamically
06:25having the links added to this menu.
06:27So I can feel a little bit confident about going ahead and doing that.
06:29Now, this technique would be a little more difficult if they were dynamically generated
06:34links in this menu or I wasn't sure exactly how many menu items I was going to have.
06:39For each list item, I'm giving them a margin right of 10%.
06:41Now, what this allows me to do is the above code centers this menu within the tablet layout,
06:47but the margin right of 10% allows the space between the list item to flex. So as the size
06:53changes, the available space changes, and these can flex a little bit.
06:58For our last child I took the margin right and got rid of it. So that's essentially saying,
07:03hey, for all of the links I want a margin right of 10% expect for the last one.
07:06Now if I go into the actual links themselves, for the mainNav a, I have got the font size
07:11at 1.2ems, I'm aligning the text to the center, and then I'm applying some padding
07:15bottom to this one at 40 pixels.
07:16If you remember, the padding left that we had on the desktop styles, here the padding
07:21is going to be on the bottom, because the icons that we're going to be displaying are
07:24going to be displaying at the bottom of those links.
07:27And then finally, for the text inside the emphasis, since we're running out of room for that,
07:31we make the decision to hide them.
07:33Now again, there are various techniques to do this. I could visibility hidden.
07:37I'm choosing to use display none.
07:40Remember that this setting actually affects accessibility. That text will not be read on
07:44a screen reader at this particular screen size, so that is something that you need to
07:47think about when you start thinking about using the technique that display none.
07:51Let's go ahead and preview that.
07:52So I'm going to save this, go back to my browser, and not only do I need to refresh my browser
07:56at this point, but I also need to resize it to trigger those.
07:59And you can see, our tag lines go away. We don't have our icons in there yet, but everything
08:03else is looking good. The menu is centered inside the tablet layout area, so that is
08:07working exactly as we intended.
08:09I am going to scroll up a little bit further, so we can tackle on mobile styles. And this
08:14one is going to be line 470, if I remember correctly.
08:19Right about there. Yeah, right around 471 or so.
08:22So again, in between the header and mission styles I am just going to create a little
08:24bit of space there and then paste in my mobile navigation styles, okay.
08:28So, these are going to be very similar to our tablet styles.
08:32First off, we start up with the mainNav, we give it a fixed width again, and we do the
08:36auto centering technique. So we are really centering it just in a smaller space.
08:39However, this time we're giving a considerably larger margin on the bottom, and that has anything
08:43to do with the mission statement following it, not having the photo. So we're just giving
08:47ourself a little bit of negative space there.
08:49The other thing that we're doing is we're lowering the amount of margin we need to the
08:52right, because we have less space. We're still stripping it from the last child, however.
08:56But then we have got a couple of things that are a little different. The font size
08:59is smaller, the text alignment is still on the center, but take a look at the padding bottom we have here.
09:03The padding to the bottom is 50 pixels, which is fairly sizable when you compare that to
09:07the tablet in the desktop layouts.
09:09Now, the reason for that has everything to do with the size of your finger. That's right--your finger.
09:13Studies have shown that the average touch, in terms of how much screen real estate it
09:18takes up, is around 44 pixels by 44 pixels, right around there.
09:22So when you're creating these target areas for your navigation on mobile devices, you
09:26need to have that number in mind, because if you have a link that is smaller than that,
09:31an icon that's smaller than that image, you know, something like that as somebody is going
09:35to select, chances are they're going to have trouble selecting it.
09:38If you also put these items too close together within that range, then they are likely to
09:43make a mistake by touching the wrong thing by accident.
09:45So that's something you want to consider when you're planning your mobile navigation.
09:49And just like our tablets, we're turning the display of our emphasis text off to hide those.
09:53So again, I'm going to save this, go back into my browser, refresh, and let's go down to our mobile size.
09:59So our menu is up here. You could see that we have the extra padding underneath it where
10:03icons are going to go. Then we have this sort of extra white space here to make that a little
10:08bit more readable so that this headline is not butting right up against our navigation.
10:12All right, that's pretty much it. For the most part, our basic menu is looking okay
10:18across all the different screen sizes, but it's still lacking all of those icons that
10:22I was just talking about.
10:23So, we need to go ahead and explore adding those icons, and we're going to do that in the next exercise.
10:28
Collapse this transcript
Using CSS sprites in menus
00:00We'll finish up our basic menu styling by adding a set of icons.
00:04When using icons in responsive designs, you have the additional consideration of icon
00:08size and how using them is going to impact your site's performance.
00:12I want to take a deeper look at this by first taking a look at the set of icons that we
00:16are going to be using for our basic menu.
00:18Now, I have opened these up in Photoshop. You don't have to do this, but if you want
00:22to open up and kind of experiment with them, you can.
00:23They are the icon_sprites_25.png. You can find this in the 03_03/_images directory.
00:31I have two sets of sprites. I have got the 25.png and the 50.png.
00:36They are exactly the same.
00:37They are just a little bit larger. The 50 is 50 x 50 pixels for each one of them, whereas
00:42the 25 of course is 25 x 25.
00:44So you can see in a sprite file, each of the icons are just sort of occupying
00:48their own space within this much larger file.
00:51What this allows me to do is by using background images, I can use the background position
00:55property to sort of only show one of these at a time.
00:59So I can define, almost like a window if you will, for the element that's displaying them,
01:03give it a width and a height or enough volume to display this, and then just sort of use
01:06background position to move these around so that only one is showing at a time.
01:10That's basically how sprites work.
01:12The reason that that's so effective for responsive design--and I will talk a little bit more about
01:16this later on in the course when we talk about the performance. But one of the reasons why
01:21this is so effective for responsive designs is it reduces the amount of HTTP requests.
01:25It reduces the amount of requests made to the server for resources.
01:29So in this case, I only have four icons, but let's imagine that we are using twenty icons within our site.
01:34Each separate icon, if you were to do them one at a time, would be a separate request to the server.
01:40Now, that doesn't mean much over a wired connection or a fast wireless connection, but over a
01:45cellular network or network where there is a lot of latency, that is an issue.
01:49So or mobile devices, all those requests to servers are really performance inhibitors.
01:54So by using sprites, we are essentially making that request a single request and then moving
01:59it around when we need to use a different one.
02:01So there's a trade-off because of course these are all going to be larger in file size
02:04because they are just bigger, but the performance enhancement that you get by reducing requests
02:09is often times very, very much worth it.
02:12So let's take a look at how to put these in action.
02:13I have opened up the index.htm, along with the corresponding main.css file found in the
02:2003_04 directory. And like most of these things, we are going to start off in the desktop style,
02:25so I am going to scroll all the way down towards the bottom and find my desktop style navigation.
02:31And it's just underneath these header styles, right around line 1110 or so.
02:35And I am just going to put these at the very, very bottom of my navigation style,
02:39so again, just above the mission styles. As we have in the past, I am just going to enter
02:43the code in, just paste it in, and then go over each line by line, so feel free to pause
02:47the video and then type all of these in. But I want to talk about what these are doing for us.
02:52You'll notice that each of these selectors is targeting a link with a specific class.
02:55When we structured our navigation, we gave each menu item its own class that identified
03:00it: gallery, gear, interact, and shop.
03:02Now we are going to take advantage of that.
03:04So we are essentially applying a background image, and it's that 25 x 25 pixel image.
03:09You will notice that for the no repeat, we have both the horizontal and vertical values
03:14for how we want to position these sprites.
03:16Now, the vertical values make sense, because you may have noticed it was a very thin sort
03:21of vertically aligned set of icons. So the three pixels--the -98, the 197, the 297--they
03:26kind of tell you how far apart these are.
03:28They are about 100 pixels apart.
03:30I have always found that as much as I try to align the icons with exactly 100 pixels
03:36apart from each other, l always tend to have to change it up just a little bit so they
03:40visually it looks centered.
03:42So it's a couple pixels off. For me it's generally just sort of knowing where it's supposed to
03:46be and then kind of experimenting around with it.
03:47You can see that the negative value move you up along the axis of the graphic itself.
03:51Now what may be confusing you there are the horizontal values, and the reason for this,
03:55remember, is that we are using centered text.
03:57So the text is center-aligned.
03:59So even though we have a little bit of padding off the left-hand side to allow for the icons,
04:03I had to do a little bit of adjusting of the horizontal value to make sure that it was
04:08accurately lined up with the text as well.
04:10So I would love to tell you that every single time I use sprites I know exactly which values
04:13to plug in, but that's not true.
04:15A lot of times I have an idea of what the values are going to be and then I have to
04:18tweak them based on how the particular icon looks with the text.
04:22So if I save this and go into my browser and refresh, I can see now that my icons are all
04:28coming into place. And they are all positioned relatively well in terms of lining up with
04:32the text the way that I want.
04:33So I am going to shrink this down to tablet size, and we can see that we don't have our icons here,
04:38so let me go back into my code, and we will tackle our tablet styling.
04:42So I am just going to scroll up again till I find our tablet styles.
04:45So around line 774 or so should be my tablet styles.
04:49Again, I am just going to give myself a little bit of space between the current into my main
04:53navigation styles and the mission styles, and I will place in my tablet sprite code.
04:58Same icons, same code for the most part. You'll notice that this time, instead of having to
05:03horizontally adjust, we're centering this horizontally, and then vertically, again,
05:08we're going down through these.
05:10These values are different as well, and the reason for that is if you remember from when
05:15we looked at the finished version of this, these icons are appearing below the text.
05:18So exactly how they're going to be positioned within that parent element is going to change
05:23to allow room for the text above it. And then the centering there horizontally is going
05:27to align it horizontally centered with the text.
05:29So if I save this, go back and I refresh my tablet view, the icons just come right into
05:35position just where I want them underneath the text. Fantastic!
05:38Now, the last one we are going to deal with is our mobile styles.
05:42So let me go back into my code, scroll up through my styles until I get to my mobile
05:47navigation, right above my mission style here, around the line 494 or so, and we will just put code in.
05:55Now, I am just going to allow you to pause this and kind of go ahead and type these out.
06:00And then I want to talk about one of the big differences here.
06:03You'll notice that the icon sprites that I am using is not the 25 x 25 pixel one.
06:07I am actually using the 50 pixel one, and there's a big reason for that.
06:09And the big reason for that again--we talked about in the last movie--that is your finger.
06:13So when somebody's finger is used to navigate or touch a device, typically the average size,
06:19research has shown it to be around 44 pixels x 44 pixels.
06:23So I wanted to make sure that I had a large enough active area to where it'd be very easy
06:27for somebody to touch and activate it, and they wouldn't be so small that they are going to miss it.
06:32So in that case I am actually going to use larger icons.
06:35Now, that seems almost contradictory to what you'd think; you'd think, oh, you're going
06:39down to a mobile screen size--you are probably going to want to use a smaller icon, when
06:43in fact, in this case we want to use larger icon so that we are giving people a nice
06:46large visible area to target for and click.
06:50And because of this file being bigger, you will notice that the vertical values for our
06:54background positioning are quite a bit more.
06:56So if I save this and go into my browser and refresh, there is our active clickable area.
07:02It also puts more emphasis on the icons themselves than the text, so it's a much more visual style
07:07of menu than we have been using before.
07:09It allows people to really visibly say okay, I want to go to the galleries, I want to check
07:13out the camera equipment, I want to shop, that sort of thing.
07:15And for a mobile context, that's actually a little bit better as well.
07:19So now we have a fully functional basic menu that operates pretty much the way that we
07:24want it to across multiple screen sizes. Even in case of a simple menu like this one,
07:29you still have a lot of factors to consider when building your menus that need to work
07:33across all these multiple contexts that we have been talking about.
07:36Just be sure to carefully plan through site navigation before you start building the site.
07:41Extra time given to those initial planning stages can really save you a tremendous amount
07:46of work later on, and that will sure that your users have effective navigation work regardless
07:51of which device they are using.
Collapse this transcript
Structuring complex menus
00:00As menus become more complex, the challenges around making them responsive grow, almost exponentially.
00:07Not only do you have to deal with a shrinking screen real estate, but you also have to deal
00:11with changes in device functionality, things like touch screens and different user expectations
00:18across different devices.
00:20So in this next series of exercises, we are going to be creating a relatively simple responsive dropdown menu.
00:25Now, as we build this, I am going to point out many of the factors that we need to consider
00:29to get our menu functioning across different screen sizes and devices.
00:34And as you'll see, even simple menus like this one can require a great deal of thought.
00:40So I'm going to start by working in the index.htm file, which is found in 03_05 directory.
00:46Our menu is going to be fairly long structurally, so again, I'll be pasting some code in and
00:51then kind of going along with you guys.
00:53But we are going to be building this in stages.
00:55So you know as I'm working, I'll explain the code, but feel free to pause the video and
00:59kind of look and see what we are doing. And where we are placing the code matters, so
01:02just be really, really careful about how you are coding along with me here.
01:06So just below the site navigation, about line 18 or so is where our first bit of code is
01:11going to go, and we'll start building our menu the way we start building almost all menus.
01:14We are just going to go ahead and put an unordered list in.
01:17This unordered list is going to have a class of topMenu.
01:21So just start by building an unordered list and then give it a class of topMenu.
01:25Now, the reason I am using that top menu class is it identifies which menu this is, and it
01:31also allows me later on to toggle that menu off and on on smaller mobile screens.
01:37So even though it's a fairly semantic class, it's got some behavioral usage there as well.
01:42Inside that unordered list, we are going to go ahead and do sort of the top level of our
01:46menu, so none of the dropdowns yet, but the top level of this. And let me kind of go over
01:52this carefully with you guys. And I am just going to apply a little bit of source formatting
01:56so this is easier to read.
01:59So inside the unordered list, here is what I want you to do. You are going to create
02:03several list items. The first list item that you are going to do is this one, and notice
02:07it doesn't have a link inside of it.
02:08It has an h3, Heading 3, with the title of Galleries.
02:12Now here's the reason that I'm using a heading instead of a link here.
02:17This is obviously going to also contain a submenu, or a subdirectory, a dropdown menu,
02:22and so with touch devices, there's some real problems in having a link actually trigger
02:28the dropdown menu, because clicking on the link obviously takes you to the page.
02:32So on touch devices you can change it so that a quick touch drops the menu down and a
02:38longer touch actually navigates into the page, but that can be fairly complex to code, and
02:43it can also be upsetting to the user if they don't really have those expectations or haven't figured that out.
02:48So it's one of those things where in this case, I can go ahead and use the h3 semantic because
02:53it's a heading of the submenu section.
02:55I am using the h3 because I'll use the h2 above it, and I can wire up the behavior exactly
02:59the way that I want it.
03:01If you don't see an h3, it's just a link, in this case going to the blog where it's
03:06just a normal link.
03:07It doesn't have a dropdown menu. So we only have three dropdown menus. We have the Galleries,
03:11the Gear, and Shop. So each one of those,
03:14notice that each one of those h3s is contained within a list item, so as you're coding this,
03:19make sure you're paying close attention to that, and you have the individual list items themselves.
03:24So now that you've completed that portion of it, we are going to go ahead and do our submenus.
03:28Now, what's really important about how you enter the submenus is where we locate this code.
03:33It needs to be inside the list item that occupies the heading that it represents, so for the first
03:38submenu, we are going to go inside the list item that contains Galleries.
03:41I am going to create a little bit of empty space below that, and I am going to go ahead
03:44and enter in our first submenu.
03:46Now, once again, I'll let Dreamweaver do its magic, apply a little bit of source formatting
03:50so this easier to read, and then scroll down.
03:52As a matter of fact, let me close this pane.
03:54That's going to be much, much better. Give ourselves a little bit more real estate for our code here.
03:59That's easier for you guys for read.
04:00So a couple of notes about this. As you guys are coding it for free, again, to pause the
04:04video and go ahead and code this, or you can pull the code over from the Finished Files
04:08folder as well, and it's not cheating.
04:10I am copying and pasting the code as well.
04:12So below the Galleries, we have another unordered list.
04:15This one have a class of submenu that identifies that this is indeed a submenu for a main menu.
04:20We have links to all of our galleries, our recent galleries, archived galleries and members' favorites.
04:25There is nothing really going on here special in terms of classes. We do have classes that
04:29identify kind of which gallery it is, but we are not really going to be doing anything with them.
04:34They are more just for semantic purposes than anything else.
04:36I am going to do my second menu now, which is going to be a dropdown menu which is below
04:41gear. So going right below gear, let me go ahead and paste that in and again apply some
04:45source formatting, just so that's a little easier to read.
04:49There we go. And now you can pause the video for just a second and code this.
04:54Again, pretty much the same thing.
04:56It has a ul, the class of submenu. We have gear, cameras, lenses, bags, favorite apps,
05:01that sort of thing, and now we have one last submenu, right down here for shop, and I am
05:06going to go ahead and put that in, apply a little bit of source formatting so it's easier to
05:11read, and then you can pause the video and go ahead and code that.
05:16So same structure, a ul, unordered list with a class of submenu. Make sure it's fully inside
05:20the list item that holds the heading that it refers to.
05:23And this one has shop, prints, clothes, and accessories. Again, nothing really out of the ordinary
05:28here, a fairly simple dropdown menu.
05:30For the most part, our menu is nice and semantic. We have got classes that identify the different
05:35submenus, the different elements themselves, and we even have a class on the top menu of
05:40a ul class topMenu to identify that as being sort of the parent menu of all of our submenus.
05:45And when you're coding these, for the most part you're going to be able to keep a really
05:49nice and semantic clean code. A lot of the dropdown menus I've seen people do for responsive
05:55menus will just be littered with just useless--not useless.
05:59They are obviously not useless, but non-semantic class names that sort of enable the functionality of the menu.
06:05I try, when I'm working, to do as little that as possible, but I'm not always able to avoid it.
06:12Case in point, what I want you to do, last thing we are going to do here to structure
06:15these is, the list items that contain the submenus, so for each one that has a heading, I want
06:20you to go ahead and apply a class of hover to those, so to each one of those.
06:27Now the reason that we're doing this has everything to do with the fact that in our tablet dropdown
06:33menus, we need to support both touch and hover events.
06:38I want to show you what I am talking about when we are entering this class of hover in and
06:42why that's necessary.
06:43So if I go out to my browser and sort of refresh my menu here, you can see that at the desktop,
06:49our dropdown menu is working fine. The styles for this, by the away, are already written,
06:54and when I go down to my Tablet Styles, you can see for tablet, galleries and gears working
07:00just fine, but shop is not yet.
07:02Now, the reason that shop is working at the desktop size but not at the tablet size
07:09has everything to do with those classes. The tablet size for tablet devices, or for this
07:15size screen, which might include netbooks or chromes, there's a lot of devices at this
07:19screen size range that support either touch or click or even both. So they may have a
07:24mouse pointer, they may have touch, and I want to be able to support those. So essentially,
07:29we are going to write a script that says, hey if touch is enabled, let's use touch for this menu.
07:33If it's not enabled, let's use hover styling.
07:36The problem is, if I use the same hover styling that I have here, then the hover styling and
07:43the touch functionality would be happening at the same time, and it would be really easy
07:46for people to register multiple events.
07:49So I have to use a different set of styles for the dropdown menu for my tablet, and that's
07:53what that particular class is doing for us. So if I go back into my code, scroll down,
07:58and get this list item here, and do class="hover" on that, if I save this now and refresh, you
08:06can see that now the dropdown menu is working there. So it's actually a different set of
08:09styles on tablet this driving that, and that's why we have to use the slightly non-semantic
08:14class of hover on those individual list items.
08:17So it does clutter up the menu a little bit, but it's not bad, and it gives us that ability
08:21later on, as we are going through these exercises, to wire up the tablet functionality a little
08:27differently than the rest of the menu.
08:29Now, I do want to point out that you are probably testing is along with me, hopefully, and thinking
08:33well, that was really, really simple.
08:34Notice that when we get down to mobile, however, the menu is gone, and that's not good,
08:38so we are going to need to fix that. And you know, you will notice that the styling for
08:42this is already done, so we are actually not going to go over how to style the dropdown
08:46menu in this particular course.
08:48If you have never built one of those HTML and CSS dropdown menus before, check out my
08:53course on CSS: Styling Navigation, where I have an entire chapter on styling dropdown
08:58menus with pure HTML and CSS.
09:00I am using the exact same technique that I covered in that course here,
09:04so it's pretty much the same thing.
09:06What we want to focus on is the functionality of that.
09:09So in the next series of exercises are actually going to be focusing on controlling
09:12the functionality and behavior of our menu, not so much styles. So here we have created
09:17this menu, and it is for the most part nice and semantic and lean, but it is worth noting
09:21that part of its structure is going to be driven by functionality. And I want to emphasize
09:25the point that when you're planning a responsive navigation like this, it's really, really
09:29important to sit down and carefully plan out all aspects of how you want this menu to perform
09:35prior to actually creating the initial structure so that you don't find yourself having to
09:39go back and modify that structure later on.
Collapse this transcript
Using jQuery for menu behavior
00:00I'm a firm believer in keeping things about as simple as possible.
00:03If it can be done through HTML and CSS alone, I'm likely to use that solution over one
00:08that uses client- or server-side scripting.
00:11However, there are times that you need scripting to help with functionality, and that's certainly
00:15going to be the case with our responsive menu.
00:18Now, for our menu, we're going to use jQuery to help the menu respond to changes in screen
00:22size, respond to click and touch events, and become more efficient in smaller screen sizes.
00:26In this exercise, we're going to create the bare bones of our menu functions and then give
00:30you a general overview of what the jQuery is going to be doing for us.
00:34Now, if you've never used jQuery before, don't panic; we're going to go through all the code.
00:38We'll type it line for line for the most part, although there will be some times where I'm
00:42pasting the code in and having you type it.
00:43But we'll still explain what the code is doing and why it's doing it, and what it's doing
00:47for us. And if you are familiar with jQuery and have used it for a while, I can tell you,
00:52you're probably better at it than I am.
00:54I don't dislike jQuery.
00:55I enjoy what it does for me, but I don't find myself staying up late at night wishing that
00:59I was programming or writing jQuery, if you will.
01:02So the very first thing we're going to have to do here, we're working in the index.htm
01:05that can be found in the 03_06 directory, and the first thing we have to do, since we
01:09want to use jQuery, is load it up.
01:12There are a couple of different ways to do this. We're going to do it the really easy
01:15way here for this portion of our course, and later on, I'm going to show you guys some
01:20loading techniques you can use to load some fallbacks in and maybe even do some asynchronous loading.
01:26Okay, so once we're done towards the bottom of our page, I'm just going to create some
01:29empty space here between the footer and the body tag.
01:32I like loading my scripts towards the bottom of the page, simply because that way the loading
01:38of your scripts doesn't interfere with the actual loading of your content.
01:43This is really kind of a long string to type out, because I want to be loading this from
01:46Google's content delivery network.
01:48Let me show you online where you can find this.
01:50If you go to developers.google.com or just to Google and search for a Google hosted jQuery,
01:55you'll find this page. And they have a list of available libraries that they host.
02:00And I'm just going to click on the jQuery link.
02:01Now, there are several advantages to letting Google host jQuery for you.
02:05One is that their content delivery server is really fast, probably faster than your server.
02:09So even though you're not hosting it locally, it's still probably going to be faster to
02:12pick it up from here.
02:13Also, they are going to make sure that you have the most recent version, that sort of thing.
02:17So I'm going to find this script tag right here for the jQuery library.
02:20I'm going to copy that, and then in my page, in that little empty space that I created
02:25down there between the footer and the closing body tags, I'm going to go ahead and paste that in.
02:29For the most part, the reason that we don't have our protocol here is because when you
02:32deploy your application or your site or whatever, it allows that your server and Google server
02:37to figure out which protocol is going to be best suited for that, whether it's the secure
02:41protocol or something else.
02:43I have found, however, that for local testing purposes, leaving that protocol off means
02:48that it doesn't get loaded.
02:49So I'm going to go ahead and add the protocol, the http to that, but if I was going to deploy
02:54this or upload this to my remote server, I would not include that protocol.
02:57So I'm going to go ahead and save that.
02:59Now that we've got that out of our way, we're ready to go ahead and start writing the scripts for our menu.
03:03Now I'm going to do that in another empty script tag.
03:06So, I'll create another script tag, an opening and a closing tag below that, and I'm just
03:11going to create a little bit of empty space to allow me to write my jQuery.
03:16Okay, so inside that script tag we're going to go ahead and do sort of the bare bones, if
03:20you will, of the functionality.
03:21The very first thing I want to do is create a variable.
03:23So I'm going to do a comment.
03:25I really like to comment out my code and if you look at the finished files, you'll probably
03:29find comments that are a little bit more involved than the ones that I'm typing in here, just
03:32in the interest of time.
03:33But I like comments. They help me understand what it is that I'm doing, and they help explain
03:37it to other team members as well.
03:39So for this comment I'm going to type in variable to hold current window state. And I'm just
03:46going to do dash small, medium, or large. And that's definitely one of the things, in terms
03:53of functionality, that we're doing here. We're going to have jQuery check the current window
03:58and see whether the user is using it on a large screen, a medium screen, or a small screen.
04:02Notice that I'm avoiding terms like desktop, tablet, and mobile.
04:05I still use them interchangeably, occasionally, but really, a medium screen size doesn't mean
04:10a tablet, and it doesn't mean a netbook and it doesn't mean a chrome.
04:12It just mean screen dimensions. Same thing for smaller screens.
04:15It doesn't mean smartphones. It just mean smaller phone.
04:18So basically, it's just going to check the size and apply the appropriate functionality
04:21for that size screen for the menu.
04:22All right, so after that, I'm going to create a variable, so I'll use the var keyword.
04:26And then right after that I'm going to go ahead and type in windowState using CamelCase for the naming event.
04:33So windowState = large.
04:36So basically, I'm establishing an initial value for this variable
04:40that's going to be large.
04:41So I'm just assuming that it's going to large, and then we'll have the functions handle whether
04:45or not it is actually large.
04:47Since we have three separate menus--we have the small, medium, and large size menus-- we're
04:51going to need to have the behavior or the functionality for each one of those controlled
04:55by a separate function.
04:56So we're going to go ahead and create the bare bones of those as well.
04:59So the first comment I'm going to do, underneath the variable, is handle menus for small screen.
05:07Then I'm going to go ahead and use the function keyword to create a function, and this function
05:11is going to be named small menu. And then I'm just going to open and close a couple of curly braces there.
05:17So function small menu, open and close your parenthesis, and then open and close that.
05:21Now, I always give myself a little bit of empty space there, and what that does for me is
05:25it just allows me to just click right in and start typing when I start building this function.
05:29I'm going to build two more functions.
05:31So, handle menu for medium screens. And this one is going to be function medium menu, so,
05:40very similar. And I'm going to do the same thing, where I'm just sort of building out
05:44the bare bones of this.
05:45And then one more, handle menu for large screens. And this is going to be a function, lgMenu,
05:55and again, I'm just going to finish out the structure of that.
06:00So I've got three functions here.
06:02There's nothing in them yet, but eventually they are going to control the functionality
06:05for the screen, whether it's small, medium, or large.
06:08Now, how in the world is the browser going to know, or the user agent is going to know,
06:12what screen size it is? Well, we have to do that function as well.
06:15So just above those three individual functions we've created and below the initial variable,
06:20I'm going to create a function that checks the state of the window size and then fires
06:25off the appropriate behaviors.
06:26So I'm going to create a comment. I'm going to say check initial width of the screen and respond
06:35with appropriate menu.
06:37On the line below that, I'm going to use the document ready function, so I'm just going
06:42to type in (document).ready. And I'm actually not going to pass the event into this.
06:48Now, I'm using Dreamweaver to kind of help me out with this, but if you've never used
06:52Dreamweaver or you're not using Dreamweaver, you don't have code hinting for jQuery,
06:56essentially you're just using the document object. You're using the ready function, so
06:59you're ready and then inside a parenthesis you do a function and then you close that.
07:05So inside that I'm going to type in a new variable.
07:07I'm going to create a variable to track screen width.
07:10So variable sw = document.body.clientWidth.
07:18So essentially, it's going to go out to the device or the browser that they're using,
07:22they're going to say, okay, what width are you, and that value is going to become a variable
07:25called screen width, which is going to allow us to check.
07:29So now we're going to do some conditional logic.
07:30I'm going to say, if screen width is less than 481. And I always like, again, starting
07:38my curly braces and ending them so that when you get into any type of situation where you
07:42are chaining together some conditionals, it's really, really easy to forget to close a
07:46curly braces or forget where you are, so I like kind of doing that.
07:49So if it's less than 41, we're going to fire the small menu function.
07:52Then we're going to do an else if, and then inside that we're going to say screen width
07:57is greater than or equal to 481 and screen width is less than or equal to 768. In that
08:09case, we're going to firing the medium menu.
08:14Now, if you're not familiar with writing jQuery or JavaScript, it is all case-sensitive, and
08:20punctuation matters.
08:21So if you start testing what you are doing a little bit later on and it's not working,
08:25go back into your code and look and make sure that you've closed all of your braces, make
08:30sure that everything is spelled correctly.
08:31Make sure that the case is correct. All that stuff matters.
08:35And then finally, we're just going to do an else, and then inside the else, we'll fire a large menu.
08:43Now, essentially, what this is going to do for us is this is going to say, hey, go ahead
08:47and check the screen size.
08:48If the screen width is less than 481 pixels, run the small menu code.
08:52If it's between 41 and 768, run medium menu; otherwise, we're going to assume we're on a
08:57large screen monitor or desktop and we'll run large menu.
09:00Now you'll notice that we're using the exact same values to check for here that we're using
09:04in our media query breakpoints, and that's really important.
09:06We want to tie the media, we want to tie the menu functionality along with the styling
09:10that we're doing as well, and we're going to use the breakpoints to do that for us.
09:13All right, so I am going to go ahead and save this.
09:15So now we have the initial structure or our menu functions.
09:17Now, before we can get into the needs of each menu, however, you may have noticed that what
09:21this function is doing for us is it's checking the initial width, but it's not dealing with
09:25the fact that somebody might resize that. So next, we're going to need to account for
09:29our screens being resized, and we'll tackle that in our next exercise.
Collapse this transcript
Responding to changes in screen size
00:00Before we can begin dealing with the functionality of the individual menus, we need to address
00:05what happens if the screen is resized.
00:07Now, in real life people don't just resize their screens as often as you see in all those
00:12responsive design demos.
00:13That always cracks me up, actually, when people demonstrate a responsive site and the first
00:17thing I do is keep resizing the browser window over and over again, and people don't really
00:20use the web like that.
00:22But however, it does happen, especially on some smaller devices when you have changes
00:26in things like orientation.
00:27So we're going to write a quick function that's going to handle any screen resizing for us.
00:31So I'm working on the index file inside the 03_07 directory, kind of picking up right where we left off.
00:37So I'm down there towards the bottom of the page inside our existing script. And I'm just
00:42going to create a new line or two, just below the document ready function, and I'm going
00:47to do another comment here, and I'm going to type in "take care of resizing the window."
00:54Or window resizing and all that, however you want to write that, all right?
00:58So what we're going to do is we're going to grab the window object and we're going to
01:02check for resize, and then inside that I'm going to type in function, and we'll go ahead
01:09and close out our function.
01:13So essentially we're saying hey, when the window is resized, let's do something.
01:16Now, the first thing I am going to do is create another variable, and I'm going to create the
01:20screen width variable, so sw, and we're going to say sw=document.body.clientWidth.
01:29So that should look fairly similar. It's exactly what we did in our last one, and it's essentially
01:33again going out and saying, okay, I want to create a new variable and I want the value of that
01:37to be the document body width.
01:38So with the clientWidth screen size, basically is what I am trying to get at.
01:41So every time the browser or the window is resized it will check and that variable will be updated.
01:46All right, so now we can do some more conditional logic.
01:49We are going to say if(sw<481 && windowState != 'small'), then I'm going to open and close
02:05those curly braces.
02:05Okay, so let's talk a little bit about what this is doing.
02:08So we are doing some conditional logic, and we're saying, okay, check the screen size.
02:12If the screen size is less than 481 pixel and the windowState !='small'.
02:18So remember, earlier we created that variable for windowState and now we can start checking
02:22it to see kind of where we are at, because if the screen is already small and somebody resizes
02:25it and it stays small, you don't want any changes to occur. You only want changes to
02:29occur if the screen size become small and that your windowState wasn't at that moment,
02:34or wasn't at the outset of that, small.
02:36And what we're going to do is we're going to fire the small menu function, so we're
02:39going to say that hey, if the screen is resized to a small size, go ahead and fire the small
02:43menu function so that it will function properly at that size.
02:47And then what we're going to do is, just below that, I'm going to do another conditional statement,
02:50and I'm going to say if(sw>480 && sw<769 && windowState != 'medium') and then once again, I'll go
03:13ahead and open and close my curly braces here.
03:16Now, for this one we're going to fire medMenu, as you probably guessed.
03:20What this is doing is it is saying, hey, if the screen width is greater than 480 but
03:24still less than 769 and the windowState is not equal to medium, let's change something.
03:30Now, you've probably noticed that above here, I'm using less than or greater than equals
03:33to, and down here I'm not.
03:35Yes, I could have done consistently, but it's just kind of six of one, half dozen of the
03:40other's personal preference. Whatever you like to do, it doesn't really matter.
03:44Under that conditional statement I'm going to do one more. I'm going to say if(sw>768 && windowState
03:59!= 'large') inside that we're going to fire lgMenu, and we'll go ahead and save that.
04:04Again, notice that we are using the same values as the breakpoints in our media queries and
04:09the same values that we used earlier.
04:12We now have just the basics of our menu functionality covered.
04:16When the file initially loads--and that's what this function is doing, above it--it's going
04:20to check the screen size and run the function that's appropriate for that size.
04:24Now, this function that we just got finished, what this one is going to do is if there's
04:28a change to the screen size, it's again going to check the screen dimensions and then it's
04:31going to run the appropriate function as well.
04:34So now that we have those bases covered, we can now move on in our next exercises and focus
04:38on the individual menu functions.
Collapse this transcript
Minimizing menus for small screens
00:00One of the biggest problems in dealing with larger menus is how to display them on smaller screens.
00:05They take up an inordinate amount of space, and if your menu is at the top of the screen,
00:10you could be forcing users to scroll all the way through your menu before they can get
00:14to what they are actually there to see, which is your content.
00:18To address that in our responsive menu, we are going to initially hide the menu from
00:21users and give them a small menu button that will then allow them to toggle that menu either open or closed.
00:27Now, there are a lot of different ways that you could approach this, so you know, the way
00:31that I choose to do it within this menu isn't necessarily the way that you might choose
00:35to do it or somebody else, and it's okay.
00:37I tend to lean towards using CSS to do as much as possible,
00:41so if I switch over to my CSS and I go down to my mobile styles--so I am looking in the
00:46main.css file in the 03_08_css directory. Say that three times as fast. It takes a while
00:53to get down here at this point, but here we go.
00:56So if I get down in to the styles, I want you to focus on two styles in particular that
01:00are going to be important to what we are doing here.
01:03The top menu, which is the actual menu itself, is the unordered list. The initial styles
01:07for it is a maximal height of zero and a visibility of it, which is why we can't see it by default.
01:13You'll notice that there is another selector below that that change the class expand span
01:17to it. So when the class expand is applied to the same element that has top menu, which
01:22will be our top menu, now max-height changes to 900 ems, which allows it to grow, and the
01:28visibility is set to visible.
01:29Now, would one of those two suffice instead of the other one?
01:32They would, and let me give you the reason why I use both of them here.
01:35One, I use max-height because you can animate maximum height using transitions.
01:39The final version of this, I am not actually transitioning or animating the menu, but max-height
01:43gives me that capability, so later on, if you guys want to experiment and play around with
01:47it, if you want to see how it would look like if that were animated, that would work just fine.
01:51One of the things I've noticed, however, on some of the iOS devices and on some of the
01:55android devices, when you set the height of element 0, you still get like one pixel's worth
02:01of that element at the very top so it makes it look like there is a border there that
02:04isn't really there.
02:06So the other thing I am doing is using visibility.
02:07I am hiding it and then using the visibility: visible.
02:10So what's going to happen is, through jQuery, we are going to create an element on the page
02:14that there is a toggle button. When somebody touches or triggers that toggle button, it's
02:18essentially going to go to the unordered list and apply the class expand to it, and then
02:21the CSS will actually handle the visibility of that.
02:25Now, that means that we're not relying on JavaScript to show and hide the element.
02:30There are a couple of reasons why I choose that.
02:32Later on when we talk about fallback methods, I am going to talk about how to make the expanded
02:36version of the menu actually the default version, so that if JavaScript is not enabled, somebody
02:41will still be able to see your menu.
02:42I've seen a lot of examples of this where jQuery and JavaScript is used to show or hide the menu.
02:47It's hidden by default and then if JavaScript is turned off, the menu just isn't going to be visible, period.
02:51All right, so I am going to go back to the index.htm file, into the source code, and I
02:55am going to scroll down into our functions.
02:58Now, we are going to start working on the small screen function, because remember, right now
03:02the behavior that we are wanting to target is the toggling of the menu itself.
03:06So I am going to go into the function for small menus. And as we've done in a couple
03:11of exercises previous to this, I am going to paste some code in, just because number
03:15one, it's faster, and number two, you really don't want to watch me make a lot of typos.
03:20And there are some really complex--not complex, but in terms of the characters we
03:24are using here, so it's just easier for me to paste it in than explain it to you.
03:27All right, so the first thing that we are going to do--I do need to tab this out so
03:31that it looks appropriate. There we go.
03:33The first thing is we are going to create the actual menu toggle itself.
03:36So the element does not exist.
03:38I didn't want to clutter up my menu with an element that wasn't going to be visible on
03:43medium screens and large screens.
03:44So I am just going to go ahead and create that.
03:46So I am going to say hey, go find that menu top menu and then before that, what I want
03:51to do is I want create this.
03:52So we are creating a div tag with a class of menu toggle.
03:56It has a link surrounding the text menu inside of it.
04:00That link literally doesn't really go anywhere.
04:01It's just a dead target link.
04:03And then we also have a span that surrounds a plus symbol and its class is indicator.
04:09Now I want to talk about that a little bit too.
04:11It's quite common when you have menus that can expand or contract to show some type of indicator.
04:15A lot of people will use a triangle that points either sideways or up or down.
04:19I like the plus and minus, and one of the reasons I like that is because I can just use text.
04:23I don't have to use icons or images with that or any type of an icon font.
04:28It's a fairly standard way of indicating that there's more there, so people are going to
04:32automatically know what it is. And then, surrounding it with a span tag,
04:35it's going to allow us to style it and sort of push it off to the right so that it's not
04:38right up against the text.
04:40Now the next thing that we want to do is we want to append that plus indicator to all of the h3s.
04:45If you remember the h3s within the menu, all those guys, they have the submenu, so they
04:50are going to be expandable as well.
04:52So I want go ahead and use that same indicator, and so I'm using the span of the class of
04:57indicator and the plus symbol and I'm appending it to that h3 so that it's going to be part
05:02of that as well, so that it will have the indicator.
05:04So that's the first two things we are doing.
05:06The next thing I want to do--and I want to go ahead and get this out of the way now--is
05:08at the very bottom of the small menu function I need to return and change the value of the windowState.
05:14Remember, the default windowState is large, so if the small menu function fires, I want
05:20to change that windowState so that any device or browser window or whatever can track
05:23it and say, okay, currently I have the small window active. So I am just going to do a
05:27comment here, and I am going to type indicate current window state.
05:34We really can just go ahead and do it for all of them if we wanted to. windowState = 'small'.
05:39And that's going to be at the bottom of every function,
05:42so the last thing we are going to do is go ahead and set the windowState once that function is fired.
05:46If I save this and preview this in my browser--and let's shrink it down--
05:54now we can see our Menu toggle is in place. So there is the word Menu.
05:58There is the plus symbol that's been appended to it.
06:00There is the div tag. Of course the styles are already written in the CSS.
06:03But if I click this, nothing happens, and that's because we haven't wired up any functionality
06:06yet, so that's what's next.
06:07Let's go back into our function and just below the existing code, I am going to go ahead and
06:13put in the second part of this.
06:15Let me even this up a little bit. There we go.
06:19And feel free to go ahead and pause the video and read through this. And in fact, what I am going
06:26to do is I am going to indent this correctly.
06:28I have a bad habit of not indenting my code correctly and having it come back to bite me.
06:34So let's talk about what this is doing.
06:36So inside that menu toggle that we've just created right here, we are going to find the
06:39link and we are going to bind a click event to this.
06:42Now you might be wondering about the different streams touch events and click events, and
06:45there is a big difference.
06:47Touch events obviously is part of the touch API, and it's wired to touch screens, and it's
06:52a specific event that happens with touch screens. Click, on the other hand, deals more with the mouse.
06:58However, most devices that are touch-enabled, the touch event, if there is not a touch event
07:03bound to an object, then the touch will replicate the click event. As a matter of fact, one of
07:07things that you have to really look out for is having both touch and click bound to something,
07:11which can cause what are called ghost clicks where you hit it and you get two.
07:15So we are binding click, and the reason we are using Click and not touch here is that
07:18there are some smaller devices like the BlackBerrys where there are pointer devices that only
07:23respond the click events and not touch.
07:25So we are going to ahead and just saying, okay, since touches register as clicks, and
07:29since clicks gives us that wider coverage, we are going to use that instead of touches--
07:32at least here anyway.
07:33When we start doing the medium one, I'll show you guys how to deal with touches so that
07:37you can form your own opinion about which ones you want to use.
07:39So we are creating another function, and what we are doing is we are going to expand the
07:43menu. So we are going to say top menu. Remember, that is the unordered list. We are going to
07:47use the toggle class method to apply the class expand to that.
07:51Now I really like toggle class in jQuery because what that does is if the class doesn't exist,
07:57it applies it; if it exists, it takes it off.
07:59So we don't have to sit there and create our own Boolean value and say, if it exists go
08:03ahead and take it off; if it doesn't exist apply it. It goes ahead and handles all the logic for us,
08:08which is what jQuery does beautifully.
08:09It just makes something so much easier.
08:11All right, the next thing we need to do is we need to keep track of that indicator.
08:15If the menu could be expanded, I want it to be a plus, but once the menu is expanded, I
08:18want it to be a minus.
08:20So we are creating a variable called new value and we are just saying, hey keep track of this.
08:24So essentially, what we are doing is we are saying hey, go up to the menu toggle and find
08:27the expand indicator and check the text, see what it equals.
08:31And so this will operator right here, hey, if it equals plus, if that's true, then the
08:36value of variable should be minus.
08:38If it doesn't equal plus, go ahead and make it plus.
08:41So this is just a way of sort of tracking it and seeing what it is and then giving different
08:45values based on what its value is.
08:47And then, using the variable that's been set, we can go find expand indicator
08:51and the text inside that expand, since it's just the plus or the minus, we can go ahead
08:55and pass along the new value of that.
08:58So if I save this and preview this in my browser and refresh the page,
09:02now when I click the menu, you can see that's toggling open and closed. Notice that the indicator
09:05is showing that there is either a menu to display or that I can collapse the menu, so that's working.
09:11And the indicators show up on our submenus as well, and that lets people know which of
09:15these menu options has a submenu.
09:17Now, if I click on these, they don't work yet, so we've still got to wire those up, but our
09:21menu toggle is working fine.
09:22So all we have to do in the next exercise is use the same logic to go ahead and add
09:27toggles for all or our submenus, and we are going to tackle that next.
Collapse this transcript
Expanding submenus through touch
00:00Touch events can be really tricky. Although you can bind both touch and click events on
00:05an object, binding both can lead to some very unexpected results.
00:09Now, there are some ways around this, but I generally like to pick one or the other, in
00:15terms of how I'm going to handle a menu or an application.
00:17Now, for our responsive navigation, I'm going to use click events for the small screens and
00:22then use touch events for the medium-sized screen; that way you can check both out and
00:26see the pros and cons of using each one of them.
00:30So we're going to start our discovery process by adding click events
00:33that are going to toggle our submenus in the small screen function.
00:37So I've got the index.htm file open from the 03_09 directory, and I've already scrolled
00:44down into our small menu function that we've been working.
00:46So we're really just sort of picking up where we left off. And what I'm going to do is I'm
00:51going to find the windowState indicator and I'm going to create a little bit of empty
00:55space above that. So this is where our next function is going to go.
00:59Now, it's really important in terms of where you place this.
01:01You want the next function that we're going to be wiring up to be outside of the closing
01:06curly braces for the menuToggle and still above the variable for windowsState.
01:12Again, I'm just going to paste some code in, and then I'm going to go over this line by
01:16line. And I'm probably going to have to adjust my spacing on a few of these items so that
01:22my indentation is correct.
01:24The first thing we're going to do is, as I mentioned, wire up the submenus.
01:28I'm going to go ahead and tab that in.
01:32We're going to find all of the heading 3s inside of topMenu and then we're going
01:37to bind a click event to them.
01:39So again, we're using click and we're not using touch.
01:42When they're clicked, we want certain things to happen.
01:44One of the first things we want to do is establish which one has been clicked.
01:48So I create a variable called currentItem, and what it does is it says, go in and find the submenu.
01:55You might be wondering why we're doing this.
01:56Well, it's the submenu that we're expanding, so I need to check and see if any of them
02:00have been expanded, because the way I want the menu to work is if somebody clicks or
02:03toggles one of the submenus open, if they click on another submenu, the first submenu should close.
02:09So one of the things we have to do is we have to sort of keep track of where we're at.
02:13What this is going to do is this is going to find the currently opened submenu.
02:18Remember, the h3 is not the submenu.
02:20That is what somebody is going to click to toggle them, but it's not the submenu itself.
02:23The submenu is a sibling of that, and it's an unordered list with a class of submenu.
02:28So essentially it's saying, hey, whoever is being clicked on, whichever h3, find any siblings
02:32that are a submenu.
02:33It's only going to have one, but it's a quick and easy way of doing that, and I'm storing
02:37that within a current item.
02:39Now, the next line underneath that is saying, go out and find any unordered list with the class of submenu,
02:46so go find all my submenus, that are not the current item and then strip off the class expand.
02:54We're using the same technique we used for the menu toggle.
02:56When a submenu is expanded, it will have the class expand applied to it; when it is closed,
03:02the expand class will be removed from it.
03:04So essentially, what we're doing is we're just doing a shot across the bow.
03:07As soon as one is clicked it's going to say, hey, go ahead and check any other submenu
03:12other than this one and if it has a class applied to it, go ahead and remove that class
03:15so those will close.
03:17So then, if we close any of those, we need to change the indicator, the plus to a minus.
03:22So again, we're just doing a very similar thing here. We're saying, hey, go find any
03:25of those h3s that aren't the one that's currently being clicked, and what I want you to do is
03:29find that span indicator and change the text to the plus symbol.
03:34So that handles taking care of any open menus.
03:36Now we need to handle the logic of actually opening that menu itself.
03:39So we're going to say, go find the h3 that's been clicked, find its sibling with a class
03:44of submenu, and then toggle the class expand.
03:47So once again, we're using the toggle class method, and this is exactly what we did with
03:51our menu toggle in the previous exercise.
03:54And then, finally, we're going to say, go and change the selected submenu indicator as well.
03:58And essentially, we just create a new variable where we look inside this, we find the span
04:03indicator text, and we did a test on it.
04:05We say, is it plus?
04:07If it's plus, make it minus.
04:08If it's not plus, make it plus.
04:10And then, we go find it and actually input that new value.
04:13So we just create a variable that says, should it be a plus or minus, and then we go in and
04:18we replace that text with whatever the new value would be.
04:20So I'm going to go ahead and save this, but this time instead of previewing it in a browser,
04:25I want to show you it in the environment that people are most likely to encounter it on, which is the phone.
04:32So I'll go ahead and open up a menu. So there are all of our submenus.
04:35You'll notice that when I click on Galleries, that submenu opens up and if I click Galleries
04:41again, it's going to close.
04:43Now, there's a little bit of animation happening, and that's being done through CSS transitions.
04:47So there isn't any jQuery animation going on there. That's all CSS.
04:51Now, if I click Gear, and Gear opens up, this time if I go up and click Galleries, notice
04:57that Gear is going to close and Galleries is going to open. Same thing if I scroll down
05:02here and click Shop, Shop will open up and Galleries is going to close.
05:06So not only am I able to toggle these menus off on and on by clicking themselves--if we
05:09hit Shop again for example, it will close-- but I could hit Galleries and then Gear, the
05:16proper one is going to open up and the other one will close.
05:18And of course, anytime that I want, I can hit Menu and it will toggle the whole menu
05:22close, so that's working great.
05:25This finishes the basic functionality of our small screen menu.
05:28We saved a little bit of screen real estate by hiding it initially, as you can see here,
05:32and we're dynamically creating these toggles and indicators to help keep our code a little bit cleaner.
05:38So next, we're going to move on to working with our medium screen size menus.
Collapse this transcript
Replacing hover styling with touch
00:00When we start scripting our medium-sized screen function we find ourselves with a little bit of a problem.
00:06While the 481 pixel to 768 pixel screen size generally means tablet or maybe even a large
00:13phone and that generally is going to be touch-enabled, the rise of netbooks and hybrid
00:19laptops means that we really can't take it for granted. And if we are really being honest,
00:24that's probably true of all the screen sizes that we are looking at: we can't tell if it's touch or not.
00:29So with that in mind, we are going to start working on our medium screen function with an
00:33eye towards making it work regardless of whether or not the device is touch-enabled.
00:39This approach we could actually use also in our large screen and small screen if we
00:42wanted to. I am just showing you a different aspect of how you can start planning for touch-enabled devices.
00:49One of things I want to point out to you really quickly, if I go over to the source code of
00:53index.htm found in the 03_10 folder,
00:57remember, back when we structured this menu, we have a few list items with the class of hover.
01:02Well, this is where they come into play and if I go over to the Main.css file, which is
01:07found in the _css directory, if I scroll down, all the way into my tablet styles, which is
01:14a little bit further down than this, notice right here, we have a selector that is going
01:21to be handling the dropdown menus if any list item with a class of hover is hovered
01:27over, or if a submenu has the class expand.
01:31Essentially, what we are going to be using, is if its touch-enabled, jQuery will go ahead
01:36and toggle that class on or off. If touch- enabled is not the case, then we'll go ahead
01:42and style it using the hover styling.
01:44Now, that also means that if touch is detected, we are going to need to strip this class out
01:50so that styling doesn't apply, because one of the dangers of using touch events is that
01:55click events and hover events can often sort of--I don't want to use the word interrupt,
02:00but it sort of registers them all at once if you will.
02:02So it's very easy, if you have both a click event or hover event and a touch event firing
02:07simultaneously, especially if you are doing a toggle, it would be very easy to hit something
02:11and then have it toggle open and close at the same time, because it registers both of
02:15them, so we will need to strip that out.
02:16So I am going to go back to my source code.
02:19I am going to scroll all the way down to our menu functions down here, to work on the medMenu
02:26function this time.
02:28Again, to save a little bit of time and typing, I am going to be pasting some code in.
02:32The first thing that we need to do is check to see if the device supports touch, and then
02:36if the device does support touch, we're going to strip out the hover styling and then add
02:40all the functionality that we need.
02:41So I am going to go and paste this code in, and I want to scroll up and go over all this
02:47code and what it's doing. And I am just going to take just a minute here to even the stuff
02:51out a little bit and make sure that my indentation makes it a little bit easier to read.
02:57So I have some comments up here.
02:58I will forgo reading those, just to tell you what this is doing.
03:01So feel free if you want to write the comments in, you can go ahead and pause the video
03:05and type this in. Just be sure that your closing brackets are handled correctly.
03:11This is the closing bracket for the medium screen function, and then this is what we just
03:16added right here that I have highlighted.
03:19So the first line is a conditional statement that checks to see if ontouchstart is available in the document.
03:26If ontouchstart is available, that means this is a touch-enabled device.
03:30So essentially, that's our way of saying, is this a touch device or not?
03:34So if this evaluates to true, we will go ahead and apply all the logic underneath this.
03:39So the first thing we are going to do is find the hover class and strip them out so that
03:42those hover events no longer trigger anything.
03:45So we go into the topMenu, we find any list item in the class of hover, and we remove it.
03:49The next thing that we need to do is actually bind touch events to the submenu headings.
03:53Now, this is a little different in terms of syntax compared to the way we were binding our click events.
03:59You will notice that we are actually using the bind method.
04:02We are going out and finding those heading threes. Remember, that heading three(h3) is
04:05the top of the gallery, the gallery header for the submenus.
04:09And we are saying I want you to bind touchstart and then once you bind touchstart, when touchstart
04:14has been detected, I want you to do this.
04:16So that's what the function is after that.
04:18So inside this function, here is what we are doing.
04:21The first thing that we are going to do is find the current submenu.
04:24So we are creating another variable called currentItem. We are finding this in the siblings submenu.
04:29So very similar to what we did earlier.
04:30We are going to have to remove the expanded class from other submenus to close any currently open.
04:35So it might seem to you that we are working backwards, like why are we closing things;
04:39we haven't even opened anything yet?
04:40But remember, these touch events can happen multiple times.
04:43So whenever you touch a menu event, you want to close any of the open menus, and that's
04:47the first thing we do.
04:49I am going to go find anything that's not the current item that's a submenu and I
04:53am going to remove the expand class.
04:55Then I am going to go in to the selected submenu, which is this siblings submenu, and then toggle that expand class.
05:01So pretty much the same logic we have been using.
05:03The difference here of course that we are binding it to a touch event rather than a click event.
05:08The very last thing I want to do here--and I am actually going to have to create a blank
05:11line to give me space to do this.
05:13So, below the touchstart closing brace but in front of the closing brace for the medium
05:19screen function, I need to indicate the current window state.
05:22So I am just going to do indicate current window state.
05:26So we have to do this for all of our functions.
05:28We will go ahead and do windowState equals medium.
05:35And that way, as soon as this function is done firing, as soon as the medium screen function
05:39is finished, it will go ahead and change that value to medium to let the device know that
05:42we are on a medium-size screen.
05:43Okay, I am going to save this.
05:45Now I want to test this, but I want to test it on my actual iPad and not in the browser
05:50window, because I want you to see this working on the touch device and not responding to clicks.
05:55So let me go ahead and switch over to that.
05:58So here I am, on my iPad, and I am just going to start touching some of these menu options.
06:02So I am going to touch GALLERIES and you'll notice that it goes ahead and opens up.
06:07Now, if I touch SHOP, it's going to open up, and notice that when I touch SHOP, GALLERIES is going to close.
06:11Now, you can also toggle these.
06:13If I touch SHOP again for example, you can see that it toggles closed. Touching it again
06:17will open it. And the same thing works for GEAR and GALLERIES.
06:23But notice that as I touch each one of these individually, the other ones close, so that works fantastic.
06:28But I'm not done, because one of the things about menus like this is, if somebody for
06:33example were to click down below the menu--let's say I clicked on this text, we're betting you do to.
06:38Let's say I click on that.
06:40Obviously I double- clicked on it and it zoomed up,
06:42so that's one thing but, most people would expect that when they click off of the menu
06:46somewhere, even to the scroll around, that that submenu would close, and it's not closing.
06:51It's remaining open.
06:52That's because right now the only way to close it is either to click on the heading itself
06:57or to click on another menu option that has a submenu.
07:01So we have one more thing left to do on our medium screen function,
07:03so let's jump back in to our code. Where we add this is very important.
07:11So what we are going to do is we need to close the submenus if the user is going to click somewhere else.
07:17We need to make sure that this code is going to be inside of the check for touch-enabled,
07:23but we don't want to do it inside of the touchstartbind function.
07:27We don't need it to fire multiple times.
07:28So I am going to create an empty line between the closing brackets of the touchstart bind
07:35function and the closing bracket for the touchstart detection.
07:39So you want it to be between those two.
07:41It's very important that you place it there.
07:42If you don't, the functionality is going to be affected severely, I should say.
07:47So now I am going to place some additional code in there, and we'll go over what this
07:51code is actually doing.
07:54The first section right here, close submenus if users click outside the menu, you can see
07:58what we are doing. We are taking the HTML element, which is the top parent-level tag,
08:03and we are binding touchstart to that.
08:04That means that no matter where somebody clicks on the screen, this touch event will render.
08:09Now, you might wonder why we used HTML instead of body.
08:13Body initially broadcasts itself as being the height of the screen.
08:17So if somebody were to scroll, there's the possibility that something below that originally
08:22visible area wouldn't actually register. HTML is going to do the entire document, no matter how tall it is.
08:27So that's a little bit of a safer choice there.
08:29So we are going to bind touchstart to that, and what we are going to do is we are going
08:33to say go to the top menu, find any open submenus, and remove that class expand.
08:39That means anywhere on the screen that somebody might touch, it's going to close the menu,
08:44including the menu itself.
08:45So you've got some logic here that says, hey, if somebody just clicks the menu, close all
08:50the menus, and that is not the way you want that to behave.
08:54So we are going to use the concept of bubbling to help us with this.
08:57So the next line right here is going to find to the mainNav. Remember, that is the actual
09:02nav element itself and everything inside of it. We are going to bind a touchstart event
09:05to that, and we are essentially going to say stop propagation.
09:09Now, if you have never worked with the concept of bubbling before, I want you to imagine
09:14the pages extruded out in three dimensions, and the background of the page is at the very
09:20bottom and then everything is sort of stacked on top of it.
09:25Think about the iPad being a glass. Like if you touched the HTML element, it's at the
09:29top and then the A element is way, way, way down there towards the bottom, nested deep.
09:35So when you click something, everything that you've touched, including the nested elements
09:39inside of it, register that event,
09:42and then that event bubbles down to the very bottom element, which might be the anchor link,
09:46and then bubbles back up. And you can capture that anywhere along the way.
09:51I could bind a touch event to the mainNav, to the unordered list inside of it, to the
09:56links inside of that, to the list items inside of that--anywhere.
09:59So essentially, at the mainNav, I'm binding a touch event and then I am saying, but, don't
10:04report further back up the chain--only go this high.
10:08That means that if you click on a link inside there, it will broadcast to the list item
10:12that it's been touched.
10:13It will broadcast to the unordered list that's been touched.
10:16It will broadcast to the navigational element, the mainNav that it's been touched, but it
10:19won't go any higher.
10:21That means everything inside the mainNav won't broadcast that it's been touched to the HTML
10:26element because we've stopped the propagation at this point, which is a very, very neat thing that we can do.
10:33So that means that everywhere else it will register this touch event but anywhere inside
10:37the mainNav, it won't come back up and broadcast to this element.
10:42So let's see that in action.
10:43I am going to go ahead and save this, and then I am going to open my iPad back up, refresh
10:48the page, and now notice that when I touch GALLERIES, it opens up; if I touch it again, it closes.
10:54Same thing for GEAR here.
10:55If I touch that, it opens up.
10:57If I touch SHOP, it opens up and then closes.
11:00So the same functionality was before.
11:01But let's say I touch GEAR and then touch somewhere down below it, under like the text
11:06here, we are betting you do too.
11:07Now when I click there, notice that that goes away as well.
11:10If I click GALLERIES and I try to zoom up, it's going to go away.
11:15Zoom back. Click it again, it will come back.
11:18And if I click, say, up here in the top of the screen, it goes away.
11:22So clicking anywhere on the screen other than the menu is going to close all the submenus.
11:27You can toggle the submenus on and off by touching them again, or you can open one submenu
11:32and close another one by touching it.
11:35Now, what's nice about this is that now, not only do we have a menu that responds to touch
11:39on this touch-enabled devices, on non- touch devices, it's still going to work as just
11:44your normal, everyday dropdown hover menu.
11:48Although we have to use a single nonsemantic class--that list item hover class--it does
11:53allow us to support both options without really a lot of overhead.
11:57Now we could certainly use this approach for the smaller screen menu as well, if you felt
12:01that it was appropriate.
Collapse this transcript
Resetting menus for large screens
00:00For the most part, we don't really need to do anything for our dropdown menu on larger screens.
00:05We have a traditional HTML- and CSS-driven dropdown that really doesn't require any scripting
00:10for it to work. And that would be great, except for the fact that we have to account for
00:15users maybe resizing their screens in a way that triggers our menus to move from one of
00:20those smaller states up to a larger one or back down again.
00:23Now in that case, we could end up with added elements and bound click and touch events
00:28that could affect both styling and performance.
00:31So, in order to make sure that our large screen menu functions properly, we're going to have
00:35to ensure that anything that may have been added by other menu functions is stripped out.
00:39So, we're going to be working in the index.htm file found in 03_11 folder.
00:44I'm just to kind of show you what I'm talking about,
00:46before we start working, I'm going to preview this in my browser. And as you can see, everything is looking okay.
00:51The dropdown menu is working just fine, just hovering over things the way that they are
00:56wont to do. But if I resize this,
00:59let's say I go all the way down, okay, to the small screen view, all right, which is still
01:03working and works fine.
01:06But let's say we resize.
01:08Now, look what happened. Whoa! Hey, look at that.
01:10So this menu shows up.
01:12We're having those indicators that show up now as well, and that's because those were all
01:15dynamically injected because the small screen function ran and there was nothing to strip them out.
01:21So that's essentially what we're going to have to do.
01:23We're going to have to account for the fact that somebody somewhere--maybe some guy doing
01:27a demo, showing the responsive website off-- would resize the screen down to that size and
01:32then back up again, and you want the menu to return to its original sort of pristine
01:35condition if you will.
01:36All right, so we're going to go back into our code and to our large menu function, and
01:39this one is pretty easy. We'll just go ahead and code all of this by hand.
01:43The first thing that we're going to do is unbind any click and touch events.
01:46So, I'm going to do a little comment here, and I'm going to say unbind click and touch events.
01:52So, you don't want those hanging around, even if you're not really responding to them anymore.
01:58The bindings can be sort of left behind and still registering and that can cause some
02:01performance issues, so we're going to strip those out.
02:04And we're just going to come in and anywhere that we've bound any touch events or any click
02:10events, we need to unbind those.
02:11So, the first thing I'm going to do is find the menuToggle a.
02:19So that's the toggle that we're actually creating earlier, and then I'm going to use the off
02:24function--or I should say the off method--to remove the click event.
02:29Now, what I really like about off is it strips everything out.
02:33So anything that might be associated with that--any functions, anything like that--it just goes and
02:36strips them all out.
02:38Next, after that, we'll go in and target the h3 as themselves.
02:41That's the headers that represent of course the top of the submenus.
02:45And that will be a topMenu h3, and then we'll use off as well there.
02:52Remember, those h3s in the medium size have touch events bound to them, and the small screen,
02:57they have click events bound to them.
02:58So, we have to strip both of those out.
03:00Now, rather than having to do this twice, you can actually use a space-separated list
03:03of events that you want unbind from this, so I'll do click space and then touchstart and
03:09then close that out.
03:11Be really careful when you do that.
03:13Make sure that this is a space-separated list, and make sure that you have a beginning quotation
03:18mark and an end quotation mark at the end of that.
03:20If you don't get the syntax right, in terms of that, it won't work, as I found out the hard way.
03:24So, make sure you do that.
03:26And then the next thing we're going to do is we're going to get rid of the listener on the HTML tag,
03:31so htm. We'll also do off there as well, and for off, we'll just do touchstart,
03:38since that's the only one we bound to that.
03:41After that, we'll come in and we'll find the MainNav, so, #mainNav.
03:48Again, we'll use off, and we'll do touchstart, because that, if you remember when we were
03:55doing the propagation, that's what we stop the propagation on.
03:58So, that's going to go ahead and unbind any touch events and any click events so that
04:03we don't have to worry about those hanging around.
04:04The next thing that we need to do is remove any of the span indicator tags, close any
04:09expanded submenus, strip out any of the classes that may have been dynamically added.
04:14So, I'm going to go down just below that--and we're still in the large menu function here.
04:18I'll type another comment, and I'll say, remove any expanded submenus. All right.
04:25So, down below that, we're going to go and find the topMenu h3.
04:31So remember, that's the headers for all of our submenus.
04:35We're going to find inside of that any unordered list with a class of submenu, and then what
04:41we're going to do is we're going to do removeClass and we're going to remove expand.
04:45So, that's going to strip out any of the submenus that might have the expand class added to them.
04:51The next thing we're going to do, I'm going to do another comment here.
04:54I'm going to say, remove the span tags inside the menu.
05:00So those span tags that we added that were menu indicators, we need to strip those out as well.
05:05So underneath that comment, I'm going to go ahead and target, once again, the topMenu h3, topMenu h3.
05:16And we're going to do a find, and we're going to find any spans with a class of indicator,
05:23and we just want to remove those.
05:26So that will go ahead and strip out any of those span tags and their contents--the pluses,
05:30the minuses, all that stuff, it will go ahead and strip those out as well.
05:34Now, that menu elements that was the toggle that shows up at the very top at the small
05:38screen, we're going to need to remove that as well.
05:40So, I'm going to type in remove menu toggle, just in case it has been added.
05:45So, we're going to target it by finding the menuToggle, and then we'll just remove it, so, fairly simple.
05:55All right, that will strip it out and remove any of its contents as well, including the links.
05:58So you don't have to do them all individually; you can just find the parent element and remove that.
06:02And then finally, at the very bottom, we're going to do what we did with the other two
06:05functions, which is to indicate the current window size.
06:09So, indicate current window state, and this time windowState is going to equal large, which
06:15is also the default if you remember.
06:17Since this is responding to the possibility that it might be resized, we need make sure that that is done.
06:22So, we'll save this.
06:23And I'm going to go back into my browser and refresh the page. All right, so that resets the menu.
06:29And now, if I resize this all the way down to, say, the small menus where we have our pluses
06:33or minuses and things like that,
06:35now if I come back up to large menu, those are now all gone.
06:38They're stripped away.
06:40We've unbounded all the click and touch events, and any of the added classes and HTML contents
06:45such as the menu toggle and the span indicators are also removed.
06:48So that goes ahead and takes care of our large screen menu, but this does kind of point to a bigger problem.
06:54Although we've avoided conflicts when screen sizes increase to the large screen,
06:59we haven't accounted for any of the conflicts that might happen between, like, some of our smaller menu.
07:05So, say when we go down to this menu and we come back up,
07:08we notice that that's still a problem as well.
07:09So, we're going to have to modify our small and medium sized menu functions in order to
07:14account for that, next.
Collapse this transcript
Preventing conflicts
00:00If users would only use our menu on one device and at one screen size, we would be all set.
00:06Unfortunately, there are times when conflicts could occur between our menus, especially
00:11if screens are resized or orientation changes, things like that. [00:00:17.0 1] Take our existing menu on an iPhone5.
00:21When I show the menu on portrait size and just kind of interact with it, it works the
00:26way you expect it to work.
00:28Submenus open and close. They animate.
00:30It depends upon which one you clicked. You can collapse the menu down again, and that's great.
00:34But now if I go into landscape mode, that's actually going to trigger the tablet styles,
00:41and you'll notice that the tablets styles aren't designed to have the menu and the indicators.
00:46Although the dropdown menu does work, you'll notice that click and touch events firing at the same time.
00:52So that's why we are getting the sort of weird effect of the submenus opening up and then
00:55closing immediately again.
00:58And even worse than these is if somebody were to use this and go, "Oh, that's horrible. I
01:01want to go back to the portrait view."
01:03And when they do this, notice what happens.
01:05Now they have two of those menu items, and every time they go to Landscape mode and come back,
01:11they're going to another one. Why?
01:14Because remember, in the small menu function, every single time that function fires, it
01:18creates one of these.
01:20A lot of times you might get something working right, and then you test it and you start
01:25thinking of some of the variables and the things that might happen, or the different
01:29ways that people might use it, and you come up with some really unintended things happening.
01:33Let's fix this, and then we'll come back and look at it after we fix it.
01:37So, I'm in the index.htm, found in the 03_12 folder.
01:41I am going to scroll down to our function, and the good news is, getting rid of those
01:46type of conflicts really isn't that difficult.
01:49And our previous exercise where we did the large menu kind of leads the way for us.
01:53So, you will notice that in order to make sure that large menu looks and behaves the
01:57way that we want it to, we strip out everything. We stripped out all the click and the touch
02:00events, and then we removed any of the added classes and removed the added content.
02:04That's essentially what we are going to do at the front end of both small and medium
02:09menu functions: we are just basically going to reset everything
02:12so that the menu has a nice fresh clean start every single time the functions fires.
02:18So what we are going to do is start at the very top of the small menu function, and I
02:22am going to go ahead and paste some code in.
02:24I want to go ahead and tab this in so that it's all looking about right. There we go.
02:30There's really not a lot here. We are just going ahead and unbinding all the touch starts
02:35and click events to all the things they have been bound to either in the small menu function,
02:40or the medium menu function.
02:42So, even if the small menu function fires over and over again, it'll continue to bind these click events,
02:47so we want to get rid of them first and then rebind them.
02:50And then the next thing that we need to do is reset the menu, in case it's being resized for
02:55A a medium screen. And again the easiest thing to do there is to go ahead and find anything,
03:00whether it's a menu or a submenu, that has the classic expand applied to it and then
03:05remove that class. And then finally, if the menu toggle has been created, remove it.
03:10That will prevent us from having four or five of those added.
03:15You could modify the comment down here to create the menu toggle. We could say now that
03:20the menu has been reset, create the menu toggle.
03:25That's maybe a little bit more descriptive.
03:27So, now I am going to go down to the medium menu function, and we are going to have to
03:31handle that as well. Again, I am going to create a little bit of space before the touch event detection.
03:36I am going to paste my code in here.
03:38Again, I am just going to space this a little bit so that it looks little nicer. There we go.
03:42So, again, we are doing essentially the same exact thing. We are not unbinding any touch
03:47events, because the small menu doesn't have touch; we are just unbinding the clicks.
03:51We are again removing the expanded class anywhere it might be found. That's going to
03:56reset any of the submenus or any of the menus that are expanded.
03:59And then we are going to move the span tags that have been added.
04:02So, we didn't necessary need to do that with the small menu, because it's okay if they
04:06stick around, but for the medium menu, we needed to go ahead and strip those out. And then
04:10finally, we are also going to remove the menuToggle if it's been added as well.
04:15And once that's all been done, we can go ahead and go back and start detecting for touch
04:20and then wiring up the behavior there.
04:22So, that's really all we needed to do.
04:24If I save this and then go back into my phone, previewing the finished page, notice we are
04:31in portrait mode and I'm interacting with the menu in my normal, regular way.
04:38But now if I go into landscape mode, we don't have all those added indicators. The menu
04:45is functioning the way it's supposed to.
04:46If I touch off the menu, it will close the submenus.
04:49If I open one submenu and click another one, again it closes.
04:53If I touch anywhere else on screen, it will close the submenus. Perfect!
04:57If I go back to portrait, it just resets the menu, starts all over again, and gives the
05:02users a very nice consistent experience, no matter what size screen they are looking at
05:08or what device you are looking on, which is exactly what we're wanting to do.
05:11We are almost done. We have one more thing, however, that we need to take care of, and
05:16that is the fact that we are relying on JavaScript maybe a little too heavily here.
05:21So in our next movie, we are going to take a look at creating a default state for our
05:26menu, just in case.
Collapse this transcript
Providing fallbacks
00:00Throughout this series of exercises, we relied on jQuery to help us provide the functionality
00:05we want for our menu across multiple screen sizes and capabilities.
00:09But we've been ignoring one very important question, what happens if JavaScript isn't available?
00:16And to prove that point I have our index. htm file here from the 03_13 folder opened in
00:21a browser and I've disabled JavaScript.
00:24Now a Desktop size, doesn't really matter, we've got a nice, HTML, CSS, driven dropdown
00:30menu, doesn't rely on JavaScript at all.
00:32Nice clean works; no big deal.
00:34However, let's go down to the mobile size.
00:39At the mobile screen size or the small screen size, JavaScript being disabled, absolutely,
00:43totally disrupts the experience.
00:46The menu is hidden by default and relies on JavaScript to show it.
00:51So, in this case that is not workable at all, same can be said if I go to tablet, we're
00:58still okay, because we have our nice drop down HTML, CSS menu, but at the mobile screen
01:03size that is going to be a bit of an issue.
01:07So, one of the things you really need to think about when you're planning any type of really
01:12complex menu like this, is how reliant on JavaScript are you?
01:17Would somebody be browsing with JavaScript turned off?
01:20And if they are, what type of experience are you providing for those guys?
01:23So, if I go back into my index.htm file, one of the things that we've done here by sort
01:30of tying the JavaScript and the CSS together is we have given ourselves a way to go ahead
01:35and give the non-JavaScript user a default experience that while maybe it's not ideal,
01:40at least it will be functional and that's the point of this.
01:43So, I am going go into our navigation and for this <ul class="topMenu">, I am going
01:48to go ahead and give it a class of expand.
01:51Now remember that the expand class in CSS is being dynamically applied to JavaScript
01:57and that's what's expanding the menu.
01:58So, if we apply this by default that means that by default this menu is going to be expanded.
02:03I want to do the same thing for the submenus as well.
02:06Let me go ahead and just apply a class of expand to each one of those, and we will just
02:14make that the default.
02:15I'll go ahead and save that, and member in all of our functions, the small menu function,
02:19the medium menu function, and the large menu function, the very first thing that any of
02:23those functions will do is strip out this class if they find it.
02:27So, if JavaScript is enabled, that's fine.
02:30It will go ahead and strip them out and the menus will appear as they would normally,
02:33but if JavaScript is disabled, let me go and save this, go back into my browser and refresh
02:38this, the menu shows up.
02:40Now it's fully expanded.
02:41It's not functional in the fact that it won't collapse and expand, but any user that doesn't
02:46have JavaScript turned on, will at least be able to see the menu and navigate it, even
02:50if it's less than ideal.
02:52However, I can promise you if they are used to browsing around with that JavaScript turned
02:56on, they are probably used to a less than ideal browsing experience.
02:59Now the real problem with this particular technique comes in with the tablet mode.
03:05So, if I expand this a little bit, you can see, again for the desktop, or large screens
03:10it's not a problem, but for tablet mode, it is a little bit of a problem, because, remember
03:13with tablet mode we were doing little bit of both.
03:16We had the hover effects still going on with the hover class, and then with the expand
03:20class, it goes ahead and sort of drops us down by default and hovering doesn't really move them back up.
03:26So, it just sort of exposes the menu.
03:28We even have a little bit of menu overlap here that's pretty distasteful.
03:32So, the real downfall to this particular approach on the tablet side is that we don't really
03:37know whether we're dealing with a touch device, or a non-touch device.
03:41If we knew, the touch wasn't a factor; we could just go ahead and do what we're doing at.
03:45The desktop level, which just simply allow the HTML, CSS to do its thing, but here at
03:50the tablet level, we don't know whether it's touch device or not and if it's a touch device
03:55and we don't have the touch events wired to the menus, and don't have them fully exposed
03:59like this, they are not going to able to browse.
04:01So this is definitely not a great solution. It's a tab level.
04:04But again, they are browsing at their size screen, and they don't have JavaScript turned
04:07on, at least they'll be able to access the menu and navigate where they want to go.
04:12Now, I'm going to be the first to admit that a non -JavaScript fallback solution is less than ideal.
04:18It is certainly more reactionary than you want.
04:21Now you may not believe me when I say this, but I sort of did this on purpose.
04:25I wanted to show you what happens when you fail the plan, any aspect of our complex system
04:32that you're building in your site.
04:33If I had designed this menu to give a decent fallback experience as a default if I started
04:39with that and then enhance the menu through jQuery at each level, I could have probably
04:44come up with a much better, much more elegant solution, than trying to shoehorn in here
04:48at the em like I did.
04:50So, trying to plan for all contingencies isn't always possible, but you need to spend time
04:54carefully considering the ways that users could encounter your navigation, so that you
04:59can at least at a minimum, always provide a clear and functional way to navigate through your site.
05:04
Collapse this transcript
Dynamically replacing menus
00:00In our previous series of exercises, we've covered how to change the presentation and
00:05functionality of a menu across multiple devices and screen sizes.
00:09While this can be extremely effective, it's not always the right option.
00:13In some cases it can actually improve usability to convert menus to other elements, like a
00:20select menu that can take advantage of a device's native user interface.
00:25I'm previewing in my browser right now the index.htm file from the 03_14 folder.
00:31I know we're back to that more simple menu, and I'm going to explain kind of why we're
00:35doing that here in just a little bit, but that's not what I want to focus on.
00:38When I scroll down, you can see that we have a list or a menu of the archived galleries for the site,
00:44so if people want to go look at the photos of Charlotte or something like that, they could go do that.
00:49In this context, within the desktop layout, within a larger-screen layout where we have
00:53a two-column layout, it fits on the screen very easy.
00:56It's really easy to sort of scan through that visually and see all the different galleries
00:59that might be available to you, so it fits this form factor really well.
01:03But when we start talking about going down to a tablet layout or to a smartphone layout,
01:07well, those are going to be single-column layouts. The users are already going to be
01:11doing a good bit of scrolling by the time they get down to that, and adding that sort
01:15of vertical height is not really the best usage of the screen space.
01:19So what I'm going to do is I'm going to show you solution that we're going to do over the
01:22next couple of exercises.
01:23I'm going to switch over to my phone.
01:26Here's the same exact file opened up in my mobile browser.
01:29I'm just going to scroll down to find that list of archived galleries and when I get
01:34down there, notice that instead of having that vertical list, I have a select menu.
01:38And it's even customized for this as well, because it says choose a gallery, which the
01:43Archived Galleries on the right-hand side does not do.
01:45So it's sort of customize for that use context.
01:47And when I select this, the phone's user interface takes over and I get to use this menu in the
01:54context that any user of this phone is going to be very familiar with. We are going to
01:58be able to quickly peruse through the cities that they are looking for without having to
02:02deal with that extra vertical scrolling.
02:05This is what we're going to be building over the next couple of exercise. We're going to
02:07take a look at how we can take some menus within the navigation and transform them into
02:12another form factor.
02:14If you're working along with me, go ahead and open up index.htm from the 03_14 folder in
02:19your code editor, and I'm just going to scroll down towards the bottom of the page.
02:23We're going to use jQuery again to help us with this operation.
02:27I've got a script tag down there at the bottom that's linking to the jQuery library from
02:31Google APIs, and then I have an empty script tag.
02:34Now, a lot of what we're going to do in this movie is very similar to what we did before,
02:38because a lot of the logic is the same.
02:41We need to check the screen size, and if somebody resizes the window, we also need to take that
02:45into account as well.
02:47So I'm just going to go ahead and start pasting in some code here.
02:49I'll go over what each line of code is doing, but it should be very familiar to you if you
02:54did the previous set of exercises.
02:57So the very first thing we're going to do is establish the default windowState.
03:00So once again, we're going to say, var windowState = large.
03:04Just after that, we have a document ready function that when the document has finished
03:08loading, is going to check the width of the screen.
03:10It's going to store that in a variable called sw, and then we do just a little bit of conditional
03:15logic--certainly not as much as we were doing before--where we say, hey, if the screen width
03:18is actually lower than 769--remember, that's the trigger for our tablet layout--
03:22go ahead and run small screen.
03:24So as before, where we had three functions-- small screen, medium, and large screen--here
03:28we really are only going to need two.
03:30We have the menu as it's going to appear in its large screen context, and then we
03:35have the menu as it's going to appear on tablets and smartphones.
03:39Right after that we need to go ahead and resize the window.
03:41We can take care of that. We're going to create another function here, and if you're
03:45coding along with me here, just pause the movie and finish writing this function.
03:50And so what this is going to do for us is it checks every single time the window is resized in any way.
03:56It's again going to create that variable for screen width, based on the width of client,
04:00and then it's going to check some really simple logic.
04:02It's going to say, hey, if the screen size is lower than 769 and the windowState = large,
04:09go ahead and run small screen, and if the screen width is greater than 768 and the windowState
04:14== small, go ahead and run large screen.
04:18Finally, we're going to create the placeholders for the two functions that we're going to
04:21be using, and for those, we're going to have two functions: one that's called small screen
04:26and one that's called large screen.
04:27I am just creating the skeleton or the placeholders for them, if you will right now. And the first
04:31one is going to convert list menus to select elements, and the second one is going to convert
04:36select elements to list menus.
04:37Now, we're going to be kind of specific in what we're doing here. We're targeting a very
04:40specific menu, but of course, you could write the functions that we are going to be doing
04:44in a very generic way so that they could go ahead and pass arguments into these functions.
04:48You could say, hey, this time I want this menu converted.
04:51Then next time you want this one converted.
04:52So there are lot of different ways that you can do what we're about to do here.
04:57This is very similar to what we did initially with our dropdown menu, and that's one of the reasons
05:00why we're looking at the simple menu version of the site rather than the dropdown menu;
05:05it's because these functions are so similar that really, if you were to externalize these
05:09scripts, you could combine a lot of what's going on here.
05:11So we are going to talk a little bit about making your scripts more efficient and externalizing
05:16them later on in the title.
05:17So for right now, I just want to be able to focus on what we're doing with the select menus.
05:22I don't want to be distracted by any of the code that was used for our dropdown menus earlier.
05:28With that basic structure intact, all we need to do now is move on to dynamically replacing
05:32the elements themselves, and we're going to start next by replacing list menus with select elements.
05:38
Collapse this transcript
Converting menus to select elements
00:00Sometimes there just isn't a very elegant way to do what you are trying to do.
00:05In the case of our Archive Galleries menu, we want to replace it on smaller screens with
00:10a select element. Although we could have two versions of the menu in our HTML and then
00:17use CSS to either hide or show them based on screen size,
00:21this would not be a very accessible or a semantic solution,
00:25so let's take a look at how we can do this dynamically through the use of jQuery.
00:29So I am working in the index.htm file found in the 03_15 folder, and you can see I have
00:36already scrolled all the way down to our small screen function.
00:38Now, what I am going to do probably won't as popular with lot of you guys that are following
00:42along with me, but there is a lot of code involved in this, and rather than trying to
00:47type every single line of this in, what I am going to do is I am going to paste the function in.
00:51Now, I am going to go through it line by line and talk about what it's doing.
00:54So at certain point, you can just sort of pause the screen and sort of type what you see here. Now,
00:58I do want you to be very, very careful because, in terms of how the code fits inside of the
01:03functions, is really, really important.
01:05But I will probably get through and tidy it up little bit after I pasted it to make sure
01:08all the indentations are where they are suppose to be and you can tell who's going with who.
01:12Now if you test the code and it doesn't work the way you've typed it in, I do have--and
01:17I will show it to over here--in the finished_ files folder of the 03_15, there's the index, and
01:22it'll give you the function that we are working with as well.
01:25All right, so let me minimize that.
01:28I am just going to go ahead and paste the code in, and let's just go through this line by line, shall we?
01:34Like I said, I may have to do a little bit of housekeeping here. It looks the way
01:38I want it to. Okay, good.
01:39All right, so let's talk about the first thing that we are going to do. So this line here,
01:43find the unordered list that you wish to change.
01:45We are being very specific, we are going in and we are saying hey, find a nav element with
01:50the class archives and find the UL inside of that or find any UL inside of that.
01:55Now, I'm using each here, and we could target it more specifically without using each, but
02:00what each allows us to do is if I had a region of the page or the entire page itself and
02:05I wanted to find a certain type of UL that maybe had a class to it called convert or
02:10select or that sort of thing,
02:11it would find each one of those and it would do this to them.
02:14So this is a little bit more flexible. For those of you that might be looking for a solution
02:18that's going to do multiple unordered lists on the page based upon the criteria you pass
02:21in, each is a little better choice for that, which is why I'm using it.
02:25So, inside this function, let's talk about what we're doing.
02:28The very first part of it is that we are creating a select element. We are doing this through
02:32jQuery and we are just saying hey, I am going to create a variable called select,
02:35so we are storing this element inside of a variable. I like this method of creating
02:39elements in jQuery,
02:40so rather than having to type out a long list of code that you are trying to create or a little
02:44string, you just say, hey I am going to do a select element, you make it self-closing,
02:48and it will go ahead and create the entire element for you.
02:50So, jQuery is good like that.
02:52So, we have created the select element now.
02:54We haven't placed it on the page anywhere; we have just created it and stored it in the variable.
02:58So that's step one.
02:59Now, the next thing that we are going to do, right here, this section of code, where we
03:03are adding an initial choice for the select element and then assigning it some attributes.
03:08So in our menu--and I'll just switch back over to the browser so you can see this.
03:11Let me scroll down a little bit.
03:14In our menu there really doesn't need to be any type of instruction given here.
03:18It says Archived Galleries.
03:19Here is a list of cities. Most people can figure that out.
03:22But for a select menu, if it said Archived Galleries and the first option was a city,
03:26that might be a little more confusing.
03:28So I would like something there that sort of gives a little bit guidance.
03:31So what I'm doing is I'm creating another variable, this one called Initial, and inside
03:36of that I am placing an option, which is each individual unit within a select menu that
03:41gives you your choices.
03:43And for this one I've put some text inside this one, Choose a gallery. So, that's going
03:47to be very first option.
03:49And I am attaching some attributes to that, so I am populating this option with some attributes.
03:53The value is going to be just a generic hash tag so if somebody selects it,
03:57it's not going to navigate off the page.
03:59And then the selected variable, the optional value of selected, its initial value is going
04:03to be selected. That's a Boolean value and that just means that that is going to be initially selected element.
04:09So, so far we have created a select element, and then we've also created an option with
04:13a couple of attributes, but we haven't joined the two together, and that's what we do in
04:17the next couple of lines of code.
04:19So I added the initial choice to the select element.
04:22So we target the select variable, which holds the select element, and then to that we are
04:26appending the initial, which is this option element.
04:29So we are placing this inside the select element we just created.
04:33Okay now, here comes the tough part. We need to populate this new select element with the
04:38links from our list menu, and I am just going to scroll up to the HTML code so you guys can see this.
04:45So our unordered list inside here, each list item has a link inside of it, the link has
04:50an HREF attribute, which goes to navigates to the page and also has a title that we can use too.
04:56So there is a couple of attributes here that we can use to populate our select menu.
05:00Okay, going back down, let's take a closer look at this function.
05:05So what it's doing is it's saying hey, go inside that unordered list that we have targeted
05:09and find every single link, find each one. And then because each is going to loop through
05:14them for us, it's going to do this for every single link that it finds.
05:18So the first thing it's going to do is it's going to create a variable called option and
05:22it's going to store in it another option element.
05:24Now initially, we are not populating the option with anything.
05:26That's what these next couple of lines of code do for us.
05:29So the first thing that we are going to do is we are going to go in to this option that
05:32we just created and we are going to set a couple of attributes.
05:34The first attributes is the value attribute, and that's going to be populated with the
05:38HREF attribute from the link.
05:40Now, there's also something else going on here that you might miss. We're taking this little
05:44option and not only we are setting attribute here, but we are also setting the HTML, meaning
05:48the content of the option, the actual text inside of it, and we are setting it to the
05:52HTML or whatever the contents of that link were.
05:55So essentially, let me kind of map out how this is working.
05:58It's saying, okay, this is going to be the value of the option element.
06:02This is going to be the actual text that's inside the option element.
06:06The option below that is setting the title attribute to the title of the links as well.
06:10Now again, all we are doing right now is creating these options and we are populating them,
06:15but we're not actually placing them anywhere.
06:17So the very next line says, okay, go up and find the select menu that we created earlier,
06:21and every single time you create one of these I want you to append it, or I want you to place
06:25it in that select element.
06:26So now we are populating that select element that we created with all of those different options.
06:32Okay, now, the next thing we need to do is handle what happens when a user selects one
06:36of these. So, we are creating a change handler for the select element, and we are saying that
06:41when somebody changes the value, what we want you to do is we want you to navigate to a
06:45new page--that's window location--
06:47and we want you to use the value that you're getting from the selected option.
06:52So we are saying hey, whichever option is selected, go ahead and grab its value--remember, the
06:56value is coming for the HREF from the links--and then navigate there.
07:00So here we have a select element that's been populated with a custom initial option
07:05and then thereafter it's populated with options that were generated from the unordered list.
07:10We're using the values of the list, such as the HREF attribute, the title attribute, and
07:15then the actual contents of the link to populate the option values for the select.
07:19But we haven't really done anything with the select yet,
07:22and that's what this very last line of code does for us.
07:25So target the unordered list and replace it with the generated select element.
07:29So here we are going to target the unordered list and then we are going to say replaceWith($select) that we generated.
07:34So you can create that select and populate it all day long, but until you do that last
07:37line of code, you haven't actually placed it on the page.
07:41And by using replace, the replace with method, we don't have to worry about putting it on
07:45the page and then removing the unordered list; we do it all in one single operation.
07:50Now, I managed to paste most of this in, but we still need to do one last little thing
07:54here. So I am going to go down to the closing curly brackets of our unordered list function,
07:59but I still want to stay inside the small screen function.
08:01So I am just going to create a little empty space right here, and I am just going to type
08:05in a comment that says, set the current window state.
08:09So just like we did when we were creating the dropdown menus, we need to keep track
08:14of the current window state, so we have that variable window state. And this one is going to equal small,
08:19so if this function is run, it's at a smaller window size so we are going to go to small.
08:22So I am going to go ahead and save this, go back in my browser, and I am going to refresh the page.
08:28So at large screens of course, nothing has happened here.
08:30But as soon as I resize the screen and I go down to, say, the tablet size, if I scroll
08:33down now, instead of seeing the unordered list, I'm seeing the select menu, and of course that's
08:37also going to be the case at my smaller screen sizes.
08:40Now, at the moment, we have successfully replaced the list menu with a select element, but if
08:46we resize the screen back up again--and scroll up to show you what happens here--oh boy!
08:53We don't get our menu back; we are stuck with that select element.
08:56So we need to take care of that using the large screen function, and we'll do that in
09:01our next exercise.
Collapse this transcript
Converting select elements to menus
00:00Now that we've successfully converted a list menu to a select element, we need to do the
00:05opposite, in case the screen is resized from a small screen to a large one.
00:10So to do that, I am going to be working in index.htm from the 03_16 folder, although
00:15we really sort of just picking up where we left off last time; so if you want to keep
00:18that file open, that's fine.
00:20I am going to scroll down and find my large screen function, and much like the last time,
00:25in the interest of time and boredom of watching me type, I am going to paste some code in
00:29here, and I am just going to scroll up and we're going to go over this line by line and
00:34talk about what it's doing.
00:35At each stage you can pause the movie, type in the code, and then we can just kind of move on together.
00:41You could probably take a good stab at doing this yourself, because really, all we are doing
00:46is sort of the reverse of what we did before.
00:48So, we are using a lot of the same methodology, a lot of the same functions and methods, but
00:52we're just sort of doing it the other way, if you will.
00:56So the very first thing we need to do is target the select menu, and to do that, we pass the--
01:01almost the same exact function,
01:03only this time, instead of targeting the unordered list, we're targeting the select element inside
01:08of the archives nav.
01:10Now, inside that we have to deal with the fact that we have an option that doesn't need to
01:15go into the unordered list.
01:18Remember, last time we created that Choose a Gallery, that initial offering, and obviously
01:23when we switch back to the unordered list, we don't need that because it wasn't part
01:27of the original list.
01:27So, the easiest way to do that is just go ahead and find the first child of that
01:33select element and then remove it.
01:34So, that will just go ahead and get rid of the original option and it won't be converted.
01:39Now, the next thing we need to do, the same way that we created a select menu last time,
01:43this time we need to create an unordered list.
01:46We use the exact some method. We create a variable, we are going to name that variable ul, and
01:50we are going to pass an unordered list into that.
01:54Now the thing that we need to do is instead of cycling through all of the links in the
01:58menu like we did last time, we are going to cycle through all the options in the select menu this time.
02:03So, we are going to say, hey, go inside the select element and find every single option,
02:08and for each one of those I want you do this.
02:10So, we are going to go ahead and for each one of those options, we are going to create
02:14a list item and an anchor element, and we are going to store them both in those variables.
02:19So, for each option it gets its own list item and its own anchor, and then we need to populate
02:25that anchor element with some attributes from the option. And this is almost exactly the
02:29opposite of what we were doing before.
02:31We are going to set the attribute href, we are pulling that from value, and then we're
02:36going a little bit further. We're saying, hey, inside that anchor element, I want you
02:40to write some HTML, and I want you to just go ahead and pass in whatever the contents
02:45of the option are, go ahead and pass that in.
02:47So, it's basically putting those things back into place, if you will. And then we are going
02:52to do the same thing with the title attribute using the same title attribute from the select
02:57to populate that anchor.
02:59Now, the next thing we need to do is we need to join all of this together, so we are going
03:02to take the unordered list and we are going to append those created list elements, these
03:07guys, into it, and then we are going to take the list items, each one of those, and we are
03:12going to append the link inside of that.
03:14So, every time we create one of this list items, it's kind of goes inside the unordered
03:18list, and every single time we create a list item, the created anchor is going to go inside of that.
03:24And that's it. That's the whole function of creating this unordered list.
03:27It's a little bit simpler.
03:29Then we have to go out and find, again, that select element, and then we are replacing it
03:33with the unordered list.
03:35So again, replaceWith allows us to do the whole two-birds-with-one-stone thing where
03:39we are replacing, we're moving the select item and then replacing the unordered list in its place.
03:44We are left to do one more thing.
03:47So, outside of that function but still inside the large screen function, remember, we need
03:51to go ahead and set the current windowState back to large.
03:54So, I am going to say set the current window state, and in this case, windowState='large'.
04:05So, I am going to save this.
04:06Now I am going to test this, but I am going to test it in my iPad, so you guys can see this working.
04:10So, here's our page previewed in our iPad and if I scroll down, I can see, just as I
04:17was expecting, I see the select menu, and clicking that gives me the select menu ui, here in the iPad.
04:23But then, if I go to my landscape mode, this actually triggers our full screen layout, and
04:29you'll notice that right over here, we have our regular, normal unordered list.
04:35And then going right back to portrait mode gets us right back to our select menu, so
04:40that is working perfectly. That's really cool!
04:42Now this wasn't that complex of a function, but if you don't feel like wiring up this
04:47type of functionality yourself every time you need to do it, it's actually pretty easy
04:50to go out online and find some prebuilt libraries that do exactly this type of conversion, unordered
04:55list to select menus and vice versa.
04:58They're typically a good bit more advanced than what I have shown you here, because they
05:01give you lot of options to place in them,
05:04but it can sometimes be a little bit harder to integrate them directly into your app or
05:07some of your site's other functionality. And if you're not using all of the functionality
05:12that they offer you, they can sometimes add a little bit of bloat to your project.
05:15So in the end, whether or not you're going to use this type of responsive navigation
05:19pattern and how you're going to create it is really largely going to depend upon the
05:24project itself and your specific goals.
Collapse this transcript
4. Creating Responsive Media
Creating fluid images
00:00Earlier in the course, we saw how background images can be very effective in responsive
00:04design, but not only giving you flexible containers that can change how much of the image they
00:09reveal, but also allowing you to swap out images at smaller screen sizes using media queries.
00:15Well, that's great if the images are purely decorative, but what if you actually need the
00:19image element itself?
00:21Images are, by their nature, a fixed size, and incorporating them into a fluid layout can
00:26quickly ruin your well-planned design.
00:28Take a look at our page here.
00:29This is the media.htm file found in the 04_01 directory. And I am just previewing it in my
00:35browser and I notice that this a two-column layout. The flexible columns, the one on the
00:41left is a good bit wider, I think, probably is 60%-70% than the one on the right-hand side,
00:47but these images are just not getting with the program.
00:50Notice that this nice image of the sailboat up here in the water at the sunset is a lot wider
00:55than the column that it's inside of it. As a matter of fact, it's just sort of forcing
00:58its way right outside of it, and it is just ignoring the flexibility of our column.
01:03We don't really have any better results over here with this picture of a flower that
01:06is inline in a paragraph. The sailboat's in its own paragraph, and I notice that when
01:11I flex here, it is just not listening.
01:15So these guys aren't behaving at all.
01:17Now, I know some of the techniques that I have been showing you guys in responsive design
01:20take a little bit of work.
01:21Thankfully though, making our images fluid doesn't take a lot of work at all, so let's
01:25take a look at some of the techniques that we can use.
01:28So, I am in my code editor here, and I have opened up the media.htm file.
01:33I just want to show you where these images are and show you a little bit of how these
01:35images are structured as well.
01:37You'll notice that the image inside the paragraph, the image of the flower there, it has a class
01:41applied to it called inline, so it is a little bit of foreshadowing; we are going to be using that in a moment.
01:46You'll also notice that that there are no width and height attributes, so if you want
01:49to make your images fluid, that's step number on.
01:52Within the code, go ahead and strip out any of those width and height attributes or just don't put them in.
01:56If you don't put them in and your images aren't fluid for whatever reason, it's okay, because
02:00the browser will take the image and just show it at its native size, so you don't really need them.
02:05As I scroll down, I can see that our other image of the sunset there in Key West is sitting
02:10inside of its own paragraph and it does not have the class of inline.
02:14Okay, so I am going to scroll right back up. And it's a very simple layout, as I mentioned.
02:18We have a 60% column on one side, 35% column on the other. When we go down below 100 pixels,
02:24we take everything down to a single column, so, very, very simple.
02:27Just above the first media query, I am going to go ahead and write our first selector, and
02:30this one is just going to be an image selector, img.
02:33So if you want to target some images specifically in your style sheets, you'd use classes or
02:38IDs or some type of specific selector, but right now we are just using the global image
02:42selector, all the images on the page.
02:44So what we are going to do is we are going to use a property called max-width, and what
02:47max-width does--and we are going to go ahead and give it a max-width of 100%.
02:50Now, you might have been tempted to say, well, what about giving it a percentage for width?
02:54Well, that would work. That would absolutely work.
02:57But max-width, on the other hand, instead of talking about the width of the image, talks
03:00about the width of the container.
03:02So what max-width is saying, it's saying hey!
03:04Whoever you're inside of, you can only be as wide as 100% of the container. So, as long
03:12as your image is actually a little larger than the container that it's inside of, your
03:16image quality is going to be fine and it is going to scale to fit.
03:19The other nice thing about this technique is that we don't have to put height auto or
03:24put any height value.
03:25The intrinsic aspect ratio of the image will be maintained by the browser.
03:30So if I save this, go back into my browser, and refresh the page, you can see what happens.
03:36Automatically, our image right up here in the right-hand column is fixed.
03:39As soon as I resize the page, it resizes as well.
03:42Now, you may have remembered how large it was when we first looked at our page, and you
03:46might think, well, wait a minute.
03:47That column is really, really small. Why did you make that image that big?
03:50Well, remember, at 800 pixels, we go down to a single column, and when I do that, it's
03:55going to show up rather large.
03:57So one of the tricks of using fluid images is understanding exactly how big this image
04:02needs to be in order to display properly.
04:04It does sort of expose one of the downsides of using this technique.
04:08You're likely going to be using a larger image than you actually need almost all of the time.
04:13You certainly don't want to have a smaller image that needs to scale up to fit that 100%
04:18of its container, because if you have that, you're going to lose image quality, and that
04:22means that on mobile devices and smartphones and tablets and things like that, you're going
04:26to make your users download a larger graphic than they actually need.
04:30But the trade-off of that is that you get an image that's going to fit anywhere, and
04:34it's going to flex right along with your layout.
04:36Now, that worked perfectly for our sailboat over here, but what about our flower?
04:40I notice that as I scale, my flower doesn't really scale at all, until it starts to already
04:45take up that 100% width, and that has everything to do with the fact that currently
04:49it's inline, so it is, along with the rest of the paragraph, is kind of doing what we told it to do.
04:56What happens when we have a situation like this, where we have an image that's inline in text?
05:00Well, first off, you're probably going to use float to wrap the text around the image in
05:04the first place. Believe it or not, that's kind of what float was designed for,
05:08so we are going to do that. And once we do that, then we can more precisely target exactly
05:13how wide we want this image to be and do it in a flexible manner.
05:16So if I come back into our CSS, I am just going to create one brand-new selector here,
05:22and I am going to use that inline class that I showed you guys earlier.
05:26So write the selector for inline, and inside that I am indeed going to float this to the
05:30right so that the text will wrap around it.
05:33I am going to give it a margin, and the margin I am going to give this is 0 for the top,
05:370 for the right, 1 em for the bottom, 2 ems for the left.
05:43So, that's going to deal with the text wrapping around it.
05:46It's going to give a little bit of space between the image and the text on the left-hand side,
05:49and it's also going to give a little space on the bottom as the text wraps underneath it.
05:54Now comes the flexible part.
05:55Now I am going to go ahead and say width, and this time instead of using maximum width,
05:58I am just going to use an actual width, and I am going to do 45%.
06:03So what that's going to do for me is it's going to say hey, this parent paragraph that
06:06you're inside of, which is filling up the entire column,
06:09I want you to only be 45% of that.
06:12So remember, when you use percentages on width, it refers to the percentage of the parent
06:17that it is inside of.
06:19And the next thing that I am going to do is I am going to set a minimum width, and this
06:22is one of the really neat parts of this technique.
06:25Specify a minimum and a maximum width for my images. So, depending upon how it fits within
06:30the layout, if it scales way up for example, you might at some point say, okay, you're
06:35allowed to flex until you get to 400 pixels wide and then stay right there.
06:39In this case, I am giving it a minimum width so that when we go down to a smaller screen
06:43size, it's not getting any smaller than that.
06:46If I save this, go back in, and refresh the page, now you can see our image is appearing
06:52at 45% of as wide as the paragraph, our margins are working, and as I resize the page, it flexes as well.
07:00Now remember, we have a minimum width of 200 pixels, so when it gets to that 200 pixels,
07:05about right there, it doesn't get any smaller.
07:07That helps it stay proportional to the text that it's inside of and never get tremendously small.
07:12Now when we go down to a single-column layout, it does the same thing. It goes down to 200 pixels
07:17and it just freezes there.
07:19Now, that might be acceptable for you, but at a really small screen size, you might think
07:23that this is a little hard to read--I know I do.
07:25So I am going to go back into our styles, and what I am going to do is I am going to go
07:29right underneath the existing media query and I am going to write another one.
07:32Now, earlier in the course, I talked about letting the content determine where your breakpoints
07:37are, and one of things I did when I was building this exercise is I started to resize my page
07:41and I said, you know, at what point should this image really sort of take over and fill
07:45up that entire column?
07:47It's when it got to a certain size and I just kind of froze the screen right there and said,
07:50okay, about right there is good and then I wrote the media query to go along with that breakpoint.
07:54So don't feel like you have to stay in the sort of dogma of, okay, 320 is mobile, 480
07:59is mobile, 726 is tablet; you don't have to do that. You can let the content drive this.
08:05All right, so I am going to say @media screen, and this gives us some good practice writing
08:11media queries as well. max-width of 550 pixels, so this time I have found a breakpoint around
08:18550 pixels. And then inside this I am going to write my inline selector again, so inline.
08:26And this time, inside of this, I am going to say float: none,
08:29so I am turning the float off.
08:32I am going to say, display:block so that it occupies its own line.
08:37I am going to give it a margin of 0 for top, auto for left and right, and 2 ems for the bottom,
08:44so that's going to center it within that space. And then, just to give it a little bit of flexibility,
08:48we are going to give it a width of 90% and a minimum width of 300 pixels.
08:53So I am going to save that,
08:56refresh my page, and now as I begin breaking it a little further down, you will
09:00notice that right when I get to this breakpoint, it goes to a display property of block.
09:05It occupies that whole space.
09:06It's got a little bit of margins underneath it there, and notice that it has a minimum
09:09width of 300 pixels, so even as I get down smaller, it's going to freeze right there.
09:19Now, there's one thing I want to point out here: the techniques that I showed you guys
09:22earlier, the maximum width technique,
09:24it's actually been around for a long time.
09:26As a matter of fact, I have got a link right here to an article by Ethan Marcotte called
09:30Fluid Images, where he talks about that technique. He wasn't the first guy to come up with it,
09:35but he really sort of expanded on it and brought it into the lexicon of responsive design techniques.
09:40But in that article he talks a little bit about supporting older versions of Internet
09:44Explorer, so if that's something that you need to do, you want to check that article out.
09:49And these techniques, as I mentioned before, they're really not that hard, but they do
09:52fail to solve many of the issues related to responsive images.
09:56For example, in order to protect image quality, your image is usually going to be a little
10:00bit larger than you actually need, and there's no real way to swap out images at smaller
10:04screen sizes if you need some sort of an editorial change.
10:07So if you resize your screen for example and when it gets really small you wanted a bigger
10:11picture of the boat, there's really no way to do that with the techniques that I have
10:14showed you here. Still, this is a very good start, and it can be a great solution in most instances.
10:20Now, for more information on responsive images and to learn more about the techniques that
10:24are evolving to solve the problems surrounding them, check out some the resource links in
10:28this exercise, as well as the additional resources movie at the end of the title. And I can recommend
10:33very, very highly The Problem With Responsive Images, by Matt Wilcox, where he goes into
10:38sort of where we are currently with responsive images and why none of the solutions that
10:42we have right now really give us the full range of solutions that we need.
10:46And then for resources, a really good way to keep up with what's going on with responsive
10:51images is to bookmark and keep checking out the Responsive Images Community Group.
10:56These guys are part of the W3C.org, and they are committed to bringing several types of
11:01solutions to responsive images.
11:04So this is a good group to track, follow, and see what they're currently doing in the
11:08field of responsive images.
Collapse this transcript
Making video fluid
00:00Much like images, video can often be difficult to integrate into responsive designs.
00:05In this exercise, we are going to explore how to embed a YouTube video into your page
00:09and then ensure it's just as fluid as the rest of your layout.
00:13So I have got the media.htm file open in the 04_02 directory, but before I can start
00:18working on this, I've got to go get a video. So, I am going to jump out to YouTube and
00:23just pick, oh, I don't know any old random video. Hey, that's me.
00:27All right, let's say I want to embed this video on one of my pages.
00:31What I would do is I will just go down to the embed link right here and I would just
00:36sort of choose some of the options here. So let's say video size,
00:38I will just pick some of the big here, 853. I am not going to show any suggest videos
00:43when the video finishes. Yeah, this is fine.
00:45All right, so I am just go and copy this and jump back into my HTML.
00:51Now, what I want to do is I want to scroll down in my code, and I am going to find this paragraph
00:55right here that says if the image is purely decorative. And I am going to create a line
00:59between those two paragraphs. Now, make sure you are outside of the closing tag or the
01:03paragraph above it and above the opening paragraph tag of the paragraph below it and then just
01:09paste that iFrame in.
01:11All right, I am going to save this. So, I am going to test this in one of my browsers and
01:16as I scroll down, oh, my goodness, wow. I like that video.
01:20I know it's just a really big one, but you can see that that video cares not one iota
01:24about our carefully crafted layout.
01:27It just is going to do its own thing.
01:29All right, so I am going to go back into my code editor, and let's take a look at how we
01:33can make that video just as fluid as our images.
01:36Now, this technique actually requires a little bit more effort than our images did.
01:41For one thing, I am going to have to take the iFrame that we place on the page and I
01:45am going to wrap a div tag around it.
01:47So right off the bat, we are doing a little bit of a nonsemantic structure.
01:50It's not the worst thing we could do, is it?
01:52So I am going to create a div tag, and I am going to give the div tag a class of video.
01:57You could call anything you want, but I think video is relatively descriptive. And then I
02:02have got to remember to close the div tag. There we go. So, I am going to save that.
02:05And then I am going to scroll up to my CSS, and I am going to create a blank line or two
02:11just above the media queries there.
02:13So last line but, just above the media query.
02:15So the first I am going to do is style the container, so I am going to say .video, so
02:19I am styling the div tag that we just created. And inside that I am going to do a position of relative.
02:26I am going to place some padding on the bottom, and this padding is going to be 56.25%.
02:34I am going to come back to that in just a moment, because that really is the key to this technique.
02:37I want to do padding top of 25 pixels.
02:43I'm going to do a height of 0 and a margin bottom of 1 em.
02:50Those may be the strangest collection of box model properties you have ever put on one element.
02:55So let's talk about what's going on here.
02:57Our position is relative because we are going to absolutely position the iFrame inside of this element,
03:01so that's the first thing.
03:03The margin bottom of 1 em is simply to keep the paragraph that follows it from butting
03:07right up against it, so it doesn't really have anything to do with the technique itself.
03:10The other three, on the other hand, are very important.
03:13First things first, padding top. Let's get that out of the way, 25 pixels.
03:17All the video players that you are going to use out there are going to have some type of chrome
03:21associated with the video that they are above and beyond the video's intrinsic ratio.
03:26So if the video, say, is 16x9 for example, the chrome might actually make it a little taller than that.
03:31I would love to tell you that I have a list for you of all the video chrome out there,
03:36but I don't, and 25 pixels was arrived at a little bit of trial and error.
03:39I have seen some people use 30. I use 25.
03:42I have seen other people use 20. You are just going to have to experiment with that until
03:45the entire video fits into the frame that you are creating for it.
03:49The real magic is the padding on the bottom.
03:52That 56.25%. If you haven't guessed already, that padding is a percentage of the parent container.
03:59Now, the parent container, remember, is the actual column that it's inside of. So, what we are
04:04doing is we are making the actual height of this, because the only thing that's driving the
04:09height since the height is at 0, is the padding on the bottom and the padding on the top.
04:13So they only thing driving the height is the width of the actual column.
04:1756.25% of that just happens due to math to give you an aspect ratio of 16x9.
04:25So, essentially what we are doing here is we are establishing an aspect ratio of 16X9 for
04:31the height of this, and it's going to have that aspect ratio in relation to the width of the column.
04:36So as the column flexes, this height will flex based on this percentage, and we will always
04:40have an extra 25 pixels or so available for the chrome.
04:45Now, you might ask yourself, well, can I just leave the height off, since it's not defined?
04:49No, not really. And one of the reasons for that is that in certain browsers, which will remain
04:54nameless, you need to trigger layout in those browsers. You need to trigger has layout and
04:58height is one properties that would do that, but height auto will not do that for you,
05:02so a height of zero is a nice trade-off without forcing our aspect ratio to be wrong.
05:07So if you're using a video that doesn't have 16 x 9, if you are using something that has,
05:11say, 4 x 3 then you'd use like--I think it's around 75%.
05:13So you just have to do a little bit of math, figure out what the percentage is for the
05:17aspect ratio, and that's what you would use for the padding on the bottom.
05:21Now we're only halfway done.
05:22I know I did a lot of explaining there, and the next rule won't take as long to explain.
05:26So the next rule I am going to do video, the video class, space, iFrame. So I am doing a descendent
05:31selector here, targeting any iFrame inside of a video element, and what I am going to
05:36do there is I am going to set the position to absolute.
05:38I am going to give it a top offset of 0 and a left offset of 0.
05:44So that's going to line the top left-hand corner of the video with the top left-hand
05:47corner of its video wrapper.
05:50The next thing I need to do is I am going to set its width equal to 100%, and I am going to
05:55set the height to 100%.
05:56I would love to tell you that it will calculate the height for you automatically as it does with images, but it does not.
06:02So you have to put that in there.
06:03So what that's going to do is it is going to position the iFrame at the top left-hand
06:07corner of its parent container and then it's going to make the width and height of that
06:10iFrame 100% of its parent container.
06:14So now, if I save this, go back into my browser, and refresh, yay!
06:18Now my video fits nicely inside my column and as I resize, the video becomes fluid right along with it.
06:26How cool is that?
06:29As with the case with our images earlier, creating a truly responsive video can be a
06:34little tricky, but this technique is going to work for you in most cases.
06:38Be sure to go ahead and check out the "Additional resource" movie at the end of the course, where
06:41I will provide a resource to a couple of libraries that deal with creating responsive video.
Collapse this transcript
Using CSS in place of images
00:00Occasionally, the correct approach to responsive images is to really not use images at all.
00:06In the case of buttons, icons, and patterns, it's sometimes just as effective to use a pure
00:11CSS solution that can solve some of the scaling and resource-management problems that plague images.
00:17To show this off, we are going to be working with the contact.htm file found in the 04_03 folder.
00:25Now, if I preview this page in a browser-- I am going to scroll down a little bit.
00:29I want you to focus on the right-hand column over here, where it says This month's contest.
00:33So right down here, we have a little link that people can click to enter our contest.
00:38I think I want to make that a little bit more attractive, maybe draw a little bit of interest to that link.
00:43In the past, I probably would use some type of an icon or an image or something there
00:48instead of just a direct link, but now with a lot of capabilities we have with CSS3, we
00:53can do that type of a graphics approach without ever using an image.
00:57So I am going to go back into the contact.htm file, and I am going to switch over to my main.css,
01:04so you can find that in the _images directory also in 04_03 directory.
01:10Now I am going to scroll down into my global styles, and I just happen to kind of know
01:15where this is already, but it's around line 381 or so. Yeah. We can see I have a little
01:21comment right there, that says /*enter button styles go here*/. All right, fair enough,
01:25I am going to get rid of that comment and just make myself a little bit of extra space.
01:30Now, this time, for the most part, I am going to be typing everything in by hand, so you
01:33probably won't have to pause the video and type it in; you can just type it in along with me.
01:37All right! The first thing I am going to do is take advantage of class that I have applied to that link
01:41and say .enter a, and then create my curly braces there.
01:47So inside the rule, the first thing I am going to do is apply a border to it. So, I am going
01:52to say border: 1px solid, and I am going to give it a color of #999, which is kind of a nice medium gray.
02:00Inside of that I am going to do a margin, and the margin is going to be 1 em for the top,
02:050 for right and left, and 1.5 ems for the bottom.
02:09The color of this, we are going to go with rgb(76, 67, 65). That's kind of a dark
02:20gray. And then for width, I am going to increase the width to 5 ems, so I'm making it a
02:26good bit wider than it would be normally.
02:28For height, I am going to make it 1.4 ems.
02:30Now you will notice that I am using relative units of measurement here. One of the reasons
02:34I'm doing that is if somebody does scale up the page--let's say they have trouble reading
02:39and they make the text size larger--then the button is going to get bigger as well.
02:42So that's one of the reasons why I am using ems instead of pixels. All right!
02:45For text-align, I am going to choose center so it's aligned in the center of our button,
02:50and for border-radius I am going to use .5 em.
02:55Finally I am going to give it a background, and the background is going to be rgb(226,
03:01226, 226), and that is going to be a light gray.
03:07Now, I am almost done.
03:09I am going to go down to the next line, and I am going to create a hover effect for this.
03:12So I am going to say .enter a: hover.
03:17So if it's a button, we definitely want some type of a hover state so that people know
03:20that they can click it, and for that, I am just going to give it a background of rgb(254,
03:28254, 254), which is almost white.
03:33So if I save this, go back into my browser, and refresh the page, now I can see my Enter
03:40button looks more like a button.
03:42If I hover over it, it goes from that sort of light gray to white. It's not bad, but
03:47it could look a little better.
03:49So I am going to back into my code and rather than make you type all this and rather than
03:54make you actually watch me type all this, I have a little surprise for you.
03:58If you go over to the assets folder--so if you're not using Dreamweaver, you are using
04:02another code editor, you can just open it up in the Explorer or your Finder window or
04:05whatever, the 04_03 directory. Find the directory that says _assets, and there is a file in there
04:11called gradient.txt. It's just a text file.
04:14So you can now open that up with text editor or whatever editor you are currently working with.
04:18So this is the syntax necessary to create the linear gradient that I am going to use
04:22for our buttons, because they would look a lot more button-like, or glossy if you will,
04:26with the right gradient.
04:28Now, before you freak totally out looking at the syntax, the syntax is really not that bad.
04:33This is actually the result of our vendor-prefix situation that we find ourselves in.
04:38The gradient syntax changed so much over just a course of a year or so that browsers really
04:44sort of struggled to keep up. The vendor prefixes had all these different syntaxes, so what you're
04:49seeing here is you are seeing one piece of syntax repeated like five or six times for
04:54different browsers and different versions browsers.
04:56The only thing that really matters is this one right here. All the vendor prefixes go away.
05:01This is the syntax that will be used.
05:03You can see we are doing a linear gradient so that means of course a gradient and a line.
05:07It's going to start from the top and go down.
05:09It's going to start with this color, an RGB with an alpha-transparency. So, notice at this
05:14point the transparency is 100%.
05:16The first break will occur at 50% down.
05:19So, you can see, we actually have several color stops.
05:21This one is at 0, this next color stop is at 50%, the next color stop is at 51%, and
05:27the final color stop is 100%.
05:29So 50 and 51, but you might think that's a little odd, but that is going to give us a
05:33line sort of right in the middle of it.
05:35So you can do as many color stops as you want inside your gradient.
05:38Now, if you are not familiar with creating gradients in programs like Illustrator or
05:41Photoshop or something like that, the term color stop might not be familiar to you, but
05:45essentially what that means is when you have a gradient, you are typically going from one
05:49color to another, but a color stop sort of interrupts that.
05:52So let's say you had a gradient starting at yellow and it went all the way down to white,
05:56but in the middle of it, you stopped that gradient with another color and you put red in it.
06:00So now you are going from yellow to red and then red to white.
06:03This is essentially what color stops do for us.
06:05I am going to highlight all the syntax right here, where it says Gradient for enter button,
06:10all that below that.
06:11I don't need this text Gradient for enter button. I just need the first background all
06:15the way down to the last background in this. I am just going to copy this and go back
06:19into my .enter a selector and paste the code right in there.
06:24It's going to look messy, but as long as you place it in the right place, just below the
06:29last background and just above the closing curly brace, you are okay. And then I am going
06:35to need to do the same thing for my gradient, for the enter button.
06:38So I am going to find it.
06:39I am going to highlight all that, copy it, go back to contact, and then same thing.
06:46Just below the top background, which is basically going to be a fallback for any browsers that
06:50don't support the gradient syntax, and then I am going to paste that in.
06:54So I am going to go ahead and save this, go back into my browser, we'll refresh the page,
06:59and now we have a much glossier-looking button. And notice that when we hover over it, we
07:03get that nice glossy look and feel to it as well.
07:06Now, not all graphics need to be images. By using some of these native CSS capabilities,
07:12you can often achieve exactly the same-- frankly, if not better--graphics than you get using
07:16an image, and you are going to have lower overhead on the page at the same time.
07:19I mean, notice for example within the browser, that if I begin to increase the size of my
07:23text, my button is going to go right up there with me.
07:28You can see, it just gets bigger with me.
07:30Now, we could do a little better job of centering it, but you get the idea.
07:34It's going to scale right along with the text.
07:37Now, before we move on, I want to point out one more thing on the page.
07:39Let me go back into the browser for just a minute and reset the size.
07:43If I scroll up, you are going to see of these social media icons over here.
07:46Now, no, these are not the best icons that have ever been created before, but these are not images either.
07:52Now, if I go back into my code and scroll up, I wasn't being a hundred percent accurate with you.
07:57They are images, but they are images that are encoded directly into the CSS.
08:02This is what's known a data URI, and essentially you take an image--in this case these were
08:07PNG files--and you base 64 encode it.
08:10Then you take that base 64 encoding, put it directly within the CSS, and then your browser
08:16can decode this and present the image.
08:18So it's really just a way of storing image information directly in your CSS.
08:23So you might be asking yourself, man, why isn't everybody doing this?
08:25Well, there are a couple of things here.
08:27First off, your base 64 encoding can really bloat your CSS.
08:31You can see, just a simple image like these icons takes up a lot of space. In fact, the
08:36code necessary for this is often sometimes larger, in terms of the actually code itself,
08:40than the image size.
08:42So sometimes you're not really gaining anything size-wise, so you just want to restrict it
08:46to smaller images, icons, and things like that.
08:49The real value that you get out of using this is the reduced HTTP requests.
08:54So for every little icon that you have on the page, or in this case these social media
08:58icons, you are not sitting there pinging the server back and forth for these images,
09:02which on mobile devices is fantastic.
09:05So you make one request via the CSS and then the images all display.
09:09So it's very, very handy for that.
09:11Generating these yourself can be pretty difficult,
09:13so there are some online generators that can help you do this.
09:17My favorite one is right here, websemantics.co.uk.
09:20It's not the best-looking site in the world, but the nice thing about this one is you can
09:24browse for an image, you can upload it, and then when you convert it, it's going to give
09:28you the base 64 encoding inside a selector.
09:31So it's very, very easy just to copy and paste it.
09:33Some of the other ones, it's a little trickier to get the base 64 encoding out, but for this one,
09:38it's really, really super simple.
09:39So, I love this technique.
09:41Just keep in mind that these data URIs, they work best for smaller graphics, but they give
09:45you that additional savings of reducing HTTP requests, so it's definitely worth your time to learn more about them.
09:51
Collapse this transcript
Image gallery overview
00:00The more that users access content across multiple devices, the more they expect that
00:05content to function in a way that's consistent with the device's capabilities.
00:10Take photo galleries for example. Not only to users expect them to display in some sort
00:14of modal window. On phones or tablets, they expect them to also be able to swipe through
00:19the images as well.
00:21Creating a responsive image gallery that takes the capabilities of multiple devices into
00:25consideration is a daunting task.
00:26In the next series of exercises, I'm going to show you how to integrate one such gallery into your site.
00:33I have opened up the finished version of the gallery that we're going to creating in a browser right now.
00:37I'm just going to scroll down a little bit to show you a few images of the city of Philadelphia.
00:40And what I like about this type of gallery is it's nice and fluid and flexible. You can
00:46scan the images really quickly and easily.
00:49It's very easy for somebody to see all the images, but if they want a closer look at
00:54one, they can hover over it. They get the nice caption that goes there.
00:57If they click it, it activates the actual gallery itself, and now, they can use their
01:01arrow keys to navigate through it.
01:02They've got the arrow on the bottom that helps them navigate through it or close it.
01:07If we go down and look at this on the actual devices themselves, say we are on a tablet for example,
01:13the captions are showing up over the images and we still get that sort of two-column layout.
01:17If you click on an image, it will go ahead and activate the gallery. And this time, in
01:21addition to the toolbar down there at the bottom, you'll notice that we can swipe through
01:25the gallery as well. And on the phone we have a similar experience.
01:29The images are showing up as a single column, and when we click on one of them it activates the gallery.
01:35And this one is touch-enabled as well. As you can notice, I can swipe through the images
01:39and it responds to orientation.
01:42It's a very flexible image gallery.
01:46Now, we're not going to be building this gallery from scratch. In fact, we're going to be using
01:50Photo Swipe, which is one of my favorite responsive image galleries on the web, if not the favorite.
01:57The reason that I like this one is because it's really how I would want to build a responsive image gallery.
02:04It allows you to build galleries that are very clean. The semantic structure is what
02:08you want to use; you don't have the use any extra elements that I've found in a lot of
02:12other image galleries out there.
02:13It has a very good fallback experience.
02:16If your jQuery is not working, if your JavaScript isn't working, if the gallery doesn't work,
02:20you still have the images on the page, and people can still click and get a larger version of it.
02:24It has a minimal JavaScript dependency. As a matter of fact, we're going to use the version
02:28that is jQuery-dependent, but it doesn't have to be.
02:31You don't have to make it jQuery-dependent if you don't want to.
02:34And it's very flexible.
02:35I can style however I want.
02:36I'm not tied to one specific graphic style, so I can integrate into any site that I want.
02:42If you are wanting to grab this for yourself, you can go to photoswipe.com. They have a video.
02:47They've got a lot of documentation. You can read up how to use them. And of course, you
02:50can also download it here as well.
02:53Keep in mind that by the time you see this series of exercises that we're going to be
02:56doing here, there could be an update available for Photo Swipe,
02:59so be sure to consult your documentation so that you'll be prepared for any changes in
03:03implementation or gallery functionality from what you are going to be learning here.
Collapse this transcript
Structuring a responsive image gallery
00:00One of the goals of any responsive image gallery is to make sure that regardless of where the
00:05gallery is being viewed, that users have access to the images, and they fit seamlessly into
00:11the responsive layout that you've crafted.
00:14So in order to do that, we're going to have to start our gallery with a really nice lean
00:19well-structured gallery of images.
00:21So, we are going to start of with the philadelphia.htm file, and you find in the 04_5 directory.
00:29I have already scrolled down to about line 31 in the HTML.
00:33There's a little HTML comment right there that says gallery goes here. I am going to go
00:37and get rid of that, and that is indeed where our gallery is going to go.
00:41Now the first thing I want to do is create a div tag to hold my gallery.
00:45I am just going to call it div class=photos.
00:49What I'm doing right now--and again this is one of the things that I love about the photo
00:52swap gallery that we are using--none of what I'm doing here structurally is being driven
00:56by the gallery itself.
00:58I can create the structure of this. The only thing I have to have our certain attributes
01:03that I'll talk about, but for the most part, I get to choose exactly how I want the gallery structured.
01:08That makes it a lot easier to fit this responsive image gallery into whatever layout I'm doing,
01:13because I'm controlling it.
01:15Now the next thing I want to do is I am going to create an unordered list, and that's a really
01:19nice logical way to structure an image gallery.
01:22It's a collection of images. In this case they are all related, so a list makes a perfect container for them.
01:27Now I am going to give this an id of photoGallery and then close my unordered list. And then
01:34each image is going to be contained within a list item element.
01:37Now I am going to do a list item, my first one, and then I'm also going to have a link.
01:42Now, the link is important for the gallery, but I would probably want the link here anyway.
01:46This link is going to be the larger version of the graphic.
01:49So, the href attribute for this one is going to be _images/gallery/philly_01_lg for (large).jpg.
02:04I'm going to give it a title. The title for this one is going to be 0street at night.
02:10And then the image that's going to sit inside this is img tag. The src for this is going
02:15to be _images/gallery/philly_01.jpg.
02:23So, same thing just without the large. This is the smaller version.
02:28This one is also going to have some alt text and the alt text for this one is street at night.
02:34What I am going to do there is close the image, close the link, and then close the list item.
02:39Now, let's take a look at the structure of this, okay?
02:42We have a list item, and inside that list item is an image.
02:45There's a link wrapped around the image.
02:47The link goes to the larger version of the image.
02:49So, if somebody were to click the image, it would navigate them to a bigger version of that photo.
02:55The title attribute of the link and the alt text are the same, and it's going to be true
02:59for every single one of these guys. And really, since we're just repeating this, you can go
03:03ahead and copy and paste this and just change the attributes.
03:05Now one more thing: I know if any of you guys are from Philadelphia you hate the term philly.
03:09I understand that, but it's a lot easier to type, so please forgive me.
03:13Now, through the magic of video editing, I saved you from having to watch me type all of that.
03:18So, I am just going to go over each one of these. You can copy and paste your previous
03:22ones and just change the values where you need to change them.
03:25You can probably guess on the images. They are going to go from 01 all the way to 08,
03:31so I am going to have eight of these.
03:32So, 01_lg would be link, 01.jpg would be the image, 02_lg, you get the idea.
03:38Now, the second one, the title for that one is going to be beautiful dome, and remember
03:41the alt text for the image is going to mirror that, so that will also be beautiful dome.
03:47For the third one, the title is going to be skyline at night, and so will the alt text.
03:51And for the fourth one, the title in the alt text will be read angels wings. For the fifth one the
03:56title in alt text will read crossing zone.
03:58For the sixth one it will be apartments for both, and for seventh one it will be construction
04:03at dusk, and finally, the last one will be liberty place. Again, it's title and alt.
04:09So you can just go ahead and pause the video for a second, type all this in. Like I said,
04:13copying and pasting can certainly speed that up a little bit, and that will be our gallery.
04:16So, if I save this and preview it in my browser, if I scroll down, you can see the gallery doesn't
04:23look all that great right now.
04:25We have the unordered list styling.
04:27It's all in one big column.
04:28However, it is functional. If I click one of these, the image comes up. Now I am actually
04:32navigating to the larger image, if you are wondering. Obviously photoswipe we haven't
04:36integrated that yet.
04:37So, even though our gallery doesn't look that great right now, it is presented in clean logical code,
04:43so our next task is going to be to add little styling to it.
Collapse this transcript
Controlling gallery styling
00:00Our gallery is in place, but it doesn't look all that great yet, as you can see here.
00:06So let's take a moment and write the general styling for our gallery, keeping in mind that
00:11we need the gallery to be responsive as well.
00:14So to work on this, I'm going to go and open the Philadelphia.htm file found in 04_06 folder.
00:21So, this is the gallery that we structured in our previous exercise and this is what
00:25I am going to be previewing up in my browser. But in order to do the styling of course,
00:29I am going to have to open up the main.css file, and that can be found in _css directory,
00:34in the 04_06 folder.
00:36Now, we have a lot of CSS to add here, so as we have in some of the previous exercises,
00:41I am simply going to paste the code, a snippet a code into the CSS file, and then kind of
00:47go over what the code is doing. So in order to write the same selectors as me, just pause
00:51the video, kind of write down what you see there, and then I will go over what's going
00:54on there. And that will just save us a little bit of time and still give us a nice thorough
00:58overview of the styles.
01:00So the first thing I want to do is affect any of the global styles. Before I start worrying
01:04about how the gallery looks like in the desktop, versus tablet, versus mobile, I am going to
01:08go ahead and style the things that are global to all of them.
01:11So I am going to go down to about line 260 or so.
01:15Yeah. Now, one of the things I want to point out to you guys is that all the gallery styling
01:20that we are going to be doing is essentially going to come right above the contact style.
01:25So when you see this comment, you know that we are in the right place. You will also notice
01:29that we already have a series of gallery styles here, but right now they are not really styling the images.
01:33They are merely styling the container itself and some of the text inside of that.
01:37Now, I am going to place my cursor right above the contact styles there, giving myself a little
01:41bit room, and I am going to write our first selector.
01:45So this selector is targeting both the unordered list and the list items inside the gallery.
01:50And essentially we are stripping out the default list styling, so, no list styling, no margin, no padding.
01:54If I save this, go back into my browser, and refresh, you can see that really all it is
02:00doing is getting rid of those little bullets that we had out beside them.
02:03It's getting rid of the list styling. And the margins and padding, we are just sort
02:07of covering our bases.
02:08Those were already stripped, but we are making sure that they were stripped.
02:12Now we can focus on the individual regions, and I am going to start with our desktop styles,
02:16so I am going to scroll all the way down, right to about line 1277 or so.
02:23So 1277, somewhere right in there, yeah.
02:26So there are our contact styles, and that is what I am looking for. So, it's really line
02:301282, but it's right around that area.
02:32I will give myself a couple lines of empty space there, and I am going to go ahead and
02:37paste in the code that we are going to need for our desktop styles.
02:40Now, there is a little bit going on here, so let me scroll back up after I get done pasting
02:44that snippet in and I will go over these rules one at a time for you.
02:47Again, feel free to pause the video, type in the selector, and then restart it, so you
02:52can hear kind of what we are doing here.
02:53Okay, so the first thing that we are targeting is an element with the class of photos applied to it.
02:57If you remember, that is the parent div tag that is surrounding our unordered list.
03:02What we are doing here is we are using the CSS 3 feature of multiple columns.
03:06Some of these are still using vendor prefixes, so we have got the Mozilla column-count and
03:10the webkit-column-count, but essentially these are the properties you want to pay attention to, right there.
03:16So column-count of 2 means inside this div tag I want a two-column layout and I want
03:211 em between the two of them, and then on the bottom of it I want 2 ems' worth of margins,
03:26and that's going to push whatever is below our gallery down a little bit.
03:29Now if we focus on the individual items themselves, if we will look at the images inside the photos,
03:34we are using the max-width technique that we learned earlier in this chapter to make
03:38sure that the images stretched to fit the width of their container.
03:42Now one of the really cool little things about CSS3 is since we are placing these images
03:46inside of a two-column layout by just using column count, that 100% now equals whatever
03:52those columns actually calculate to.
03:55So that's a really neat way of getting responsive of images that fit within a space and not
03:59really having to worry about doing too much of the math there. We're letting the browser do
04:03that for us. And then the margin bottom of a half of the em is going to keep the images
04:08away from themselves by a half em.
04:11And then the photos li, this is going to target the list items inside of our list, and notice
04:16that we have position relative, float of none.
04:19The float:none is canceling out any of the existing list item styling that may propagate down to it.
04:25So essentially, it's going to say hey, if I messed up somewhere and I wrote styling on
04:29a menu to float all of my list items, let's just strip it off, just in case.
04:35Position relative allows me to take anything inside this gallery and use absolute positioning,
04:39and it will still be relative to the list item.
04:41All right, if I save this, go out to my browser and refresh, we can see the images are now
04:47flowing into a two-column layout.
04:49They are stretching to fit the columns based upon the maximum width, and the margins that
04:53we are using there are giving us our spacing.
04:55Now, you might be wondering, yeah, but you gave a 1 em space between the two columns
04:59and you gave a half em space below them, so what's going on there?
05:02Well, remember, margin collapsing only happens when the margins touch each other, and since
05:07these are applying to the images which are inside the list items, they don't really touch
05:10each other, so we don't have margin collapse.
05:13So that half em margin is actually giving us one em total, which is giving us equal
05:17spacing between our images and beside each other as well, so it's a nice little trick.
05:20I am going to scroll up to our tablet gallery styles. The line we are looking for is around
05:25line 951 or so, right above our contacts there. And I am just going paste in my tablet styles.
05:32Once again, I am going to scroll up and go over each one of these. Now you will notice
05:37that for the most part, the code is exactly the same: photos, photo image, photo lis.
05:41As a matter of fact, you can copy and paste it in if you'd like. The only difference that
05:45we have going on here is that the column gap itself is now half em too. Because we are shrinking
05:51the size on those tablet screens, that is going to shrink as well.
05:54If I save this, go back in the browser, and resize so that I trigger my tablet layout--
06:00let me refresh the page--and you can see that now our tablet layout is also using the two-
06:06column layout as well.
06:07Now I am going to scroll up to my mobile styles, about lines 608 or so, right here, and paste
06:14those in. And you are going to notice pretty much the same selectors, except for the fact
06:19that this time we are not actually targeting the photo's container.
06:22We are setting the images maximum width to 90%, because the container is going to be
06:26100%. So instead of a two-column layout now, we are just going to have a single-column layout.
06:29So we are telling the images to be 90% of their parent, we are centering them using the auto margin technique,
06:34we are having them display as blocks so that they display on their own line, and we are
06:39spacing them using that .8 em bottom margin.
06:42For the list items inside of photos, we're giving them a position of relative and floating
06:45them as none, so that remains the same as well.
06:47I am going to save that, go into my browser, shrink that down so that it triggers the
06:52mobile layout, and refresh my page.
06:54There we go. So now our styles take effect, and you can see that we are getting a single-column layout.
07:01We still have one last thing to do for all of our layouts.
07:04I don't know if you remember, but when we previewed the finish version of the gallery
07:07earlier, we had captions that were showing up.
07:10So I want to go ahead and display those captions.
07:12I can do that using CSS rather than JavaScript. I'd really like to do that.
07:16As little dependency on the external JavaScript as possible is kind of the way
07:21I like to do things.
07:22So what I am going to do, I am just going to stick with our mobile styles for the moment.
07:26Just below the styles that I just pasted in here, I am going to add another selector, and
07:33this one is using generated content.
07:35So it's going to say, hey, gallery, so I am being really specific here, so I make sure
07:39that I'm overriding anything else.
07:41I am just adding to the specificity of the rule.
07:43I'm saying okay, any link after that link-- so this is going to insert generated content
07:48at the end the link. And for the content, instead of a literal string, I am going to
07:53tell it to place in an attribute, and the attribute I am looking for is the title of the link.
07:58If you remember, the title attribute for the links and the alt tags of the images are the exact same thing.
08:04Partly that's for accessibility; partly it's because now I knew I wanted to use this technique.
08:09Now the generated content, that title that gets placed,
08:11I am displaying it as block, so that it'll stretch to fit the width its container.
08:15I wanted its width to be 90%, which is the same as the image.
08:19I'm positioning it using absolute positioning, giving it a top position of 0 so that it
08:23lines up with the top of the image, and I'm getting a left offset of 5%.
08:27Remember, since its width is 90, that left of 5% is going to line it up directly with
08:33the left-hand side of the image.
08:35I give it a line-height of 2 ems to control the height and center the text in the side
08:39of it, gave it a color of white, text-align center so the text will be horizontally centered in it.
08:44I give it a dark background, that rgba 25, 25, 25, with 80% alpha, and then I gave it
08:51a z-index of 500 so that it's always going to be on top of the images.
08:54Now, if I save this and refresh my page, you can see the captions now come in.
08:59There is our generated content, and they line up and stretch to fit the same width of the image.
09:04There might be a little overlap depending upon the browser you are looking at, but for
09:07the most part, it's going to fit there pretty nicely.
09:11So now I just need to do that for both my tablet styles and my desktop styles, so I
09:16am going to scroll down to our tablet styles, and we are looking for right around line 991 or so.
09:22It's somewhere in that area, depending upon how you have done this so far. Just make
09:26sure I have the right one in.
09:28Okay, now the selector is going to be the same, and for the most part all these are going
09:31to be pretty much the same.
09:32You will notice that again, we are using the generated content from the title attribute,
09:37The width this time is going to be 100% because we want to stretch to fit the width of the
09:41column. The position is going to be absolute, which is lining it up with the list item
09:44The top and left of 0 are going to align it up at the top left-hand corner of the list
09:48item. line-height is again 2 ems, the color is white, the text-line is centered, so everything
09:52else is pretty much the same for that.
09:54If I save this and switch back to my tablet layout and refresh the page, now you can see
10:00the captions are coming in on that.
10:02Now, on the desktop, however, I wanted to do something a little bit different.
10:06On the tablet and the mobile screens, they don't really support hover styling, and I don't
10:12want somebody to have to touch the image in order to see the caption.
10:14I am going ahead and making them show up by default.
10:17However, on the desktop, it's pretty common for people with pointers to just hover over
10:22these gallery images. So I am going to go back into my code, so I am going to scroll
10:26down to our desktop styles, which for me is right around line 1352 or so. I am going to
10:32go ahead and paste in my rule. Now, this one is a little different.
10:35You will notice for example, that instead of just the generated content pseudo selector here after,
10:40I am also using hover, so I am just chaining those together.
10:43It's going to be a:hover:after.
10:46The rest of the code is exactly the same.
10:48The only other change is I am making is the line-height about 3 ems.
10:51That's just to make it a little bit taller when somebody is hovering over it, so it draws
10:54more attention to it.
10:55I am going to go ahead and save that, go back out to the browser, and refresh my page. I'm going to
10:59resize it till I come up to the desktop and as I hover over it, now we can see the captions showing up.
11:06Now, we have this really nicely styled image gallery that resizes, well, really all they
11:12way down to mobile. It goes from two columns to two columns to a single column.
11:15There are captions displayed when we want them to, so that's awesome!
11:19It's linking to larger version of the image, which is going to save on resources. We are
11:22not going to download them until we need them, and it displays the image captions based on
11:26the context with where it is viewed.
11:28So overall it's really, really successful.
11:29Now the only thing missing right now is that photo swipe functionality, of opening up the
11:33larger images on a mobile window and then on smaller devices, allowing us to swipe through it.
11:38So in the next exercise we are going to start adding that functionality.
Collapse this transcript
Adding image gallery functionality
00:00All we need to do to finish our gallery is add the photo swipe functionality to it.
00:05Now, while this process is pretty straightforward and they give you plenty of examples on their
00:10site to learn from, there are still a few things that you are going to need to pay attention
00:14to, in terms of integrating it into your own projects. And sometimes that's the hard part.
00:19You'll download this, you'll expand all the assets, and then it's kind of like okay, now what do I do?
00:24It's actually a really easy process. There are just a couple of things you need to track.
00:27You'll notice that I'm not in any one particular program.
00:29I'm just kind of out here in a new Finder window.
00:32So open up Explorer, if you are on a PC, Finder window if you are in a Mac, and focus on
00:37the 04_07 directory.
00:40If you open up the assets folder inside of that, you'll find a download from photo swipe.
00:45Now again, this is using 305, in terms of the version.
00:48If a new version has been released in between now and when you watch the video, then if
00:52you downloaded it, of course you'll see a little bit different version and maybe some
00:55different organization inside of it, but for the most part what we're doing here is
00:58exactly what you are going to need to do.
01:00So if I open this up it can get a little bewildering, because there's all the stuff going in here,
01:04like how much of this do I need?
01:05And what do I really need?
01:07So there are a couple of things that we're going to be doing here.
01:09First off, I'm going to grab the code.photoswipe.jquery-3.0.5.js.
01:14Now I'm not going to use the minified version of it, just so that if you ever wanted to
01:18in there and look at the functionality, you could.
01:20For deployment, you would want to use the minified version of that.
01:23I'm also going to open up a library folder right here and select the klass.min.js.
01:30Now it's simply a small library that helps people write and instantiate classes in their
01:36own applications, and so photo swipe uses klass.
01:40It's one of its dependencies, so we want to have both of those.
01:44So I'm going to go ahead and copy these, and in my own _scripts folder right here, which
01:49is where I like to put all my scripts in one place,
01:52I'm going to go ahead and just paste those right inside that.
01:56I added the klass and the photoswipe jquery version.
02:00Now, if you're wondering why we're using the jQuery version instead of just regular JavaScript version,
02:05the jQuery version works across broader platforms.
02:08The non-jQuery version really targets WebKit and iOS devices, so I wanted a little bit of a broader base.
02:14It also means that we're going to have a dependency upon jQuery and it will be a little bit larger,
02:19but I think the additional functionality across different platforms will be worth it.
02:23I also need to grab the photoswipe.css file, and I'm going to copy that into the _css directory.
02:31So that should have both my main.css and the photoswipe.css now. And there are few images that I need.
02:37I need the loader.gif, which will display if the gallery is taking a long time to load.
02:43I also need to grab the icons, both of these. The 2x is for retina displays.
02:48The regular icons are just for your everyday nonretina display.
02:52These are sprite sheets, so they're using CSS sprites as well. And I'm going to grab the error.gif.
02:58I guess I should say a gif file.
03:01So I'm going to grab those, copy them, so these are all the images. And I'm going to
03:06paste them inside of my _images directory.
03:10Okay, so that's all I really need from the photo swipe download in order to integrate
03:16it into my project.
03:18You'll notice that I am changing the way that they have organized their files so that it
03:23fits with the way that I like to organize them, and there's nothing wrong with you doing that.
03:27If you want to keep it the same way they've got it, that's okay; you can copy those directories,
03:31but just remember that it's probably not going to fit your organization to a T.
03:36All right I'm going to go back into Dreamweaver now, and I'm focusing on the 04_07 directory,
03:42and I'm going to open up the philadelphia.htm file.
03:45Now, this is the file of course that contains our gallery, and this is the one that we need
03:49to integrate photoswipe into.
03:51The first thing I want to do is link to the style sheet.
03:53So I'm just going to come up, grab my existing style sheet link, and paste it.
03:58Yes, I am that lazy. And I'm going to type in photoswipe.css and save that. And as a
04:06matter of fact, I'm going to refresh this so that I get this up here in my related files. Awesome!
04:11And now I need to do one more thing in the CSS. Because we've moved things around, the
04:18references to external things like graphics have changed now.
04:22So for example, here I'm going to go through and I'm going to find any reference to an image.
04:27Now thankfully, the CSS here is very, very small.
04:30There is loader.gif.
04:32I'm going to do ../_images/, and I'm just going to copy this path and then paste that for
04:41each one of these guys.
04:42So if we had not done this, when we looked at the gallery online we wouldn't see our images.
04:46So you got to make sure that the path to the images, regardless of where you place them
04:50within the CSS, the path knows how to find them.
04:53So I'm just going to keep looking and finding images.
04:55They're aren't that many, but there's one more left. There is icons.
05:00I'm going to paste that in front of that. And one more towards the bottom. It looks good.
05:06You can see how minimal the CSS is here. And if there is anything going on with the gallery
05:10that you don't like, color-wise, or things like that, it's pretty easy to change.
05:14Let me go back to my source code, and I'm going to scroll down to the bottom of the page.
05:18The only thing that we have left to do now is call the external resources for our photo
05:23gallery and then instantiate a new photoswipe object, and that's easy enough to do.
05:30So what I'm going to do is I'm going to copy the one of the existing script tags here and
05:35I'm just going to change some stuff.
05:36I'm going to do a little cheating and if you're not using Dreamweaver, you probably won't
05:40be able to do this, but this is really easy for me to do.
05:43It's so easy to mistype some of the stuff, so I'm just going to copy the name of the file that I need.
05:48Actually, in this case, I need klass first.
05:50So the klass minified, I'm going to copy that, and I'm going to replace the jQuery call with that.
05:58So that's really all I'm doing here.
05:59I'm going to do the same thing underneath that.
06:01I'm just going to copy the script tag and paste it in. And again, I'm going to make
06:06sure that I have the title of the code swipe correct, by pasting it in there.
06:11Now, if you downloaded a different version of that, or if you're using the minified version
06:15of it, make sure that the title of file is correct.
06:18So we're going to call klass first, because photoswipe has some dependencies on it, and
06:22then photoswipe after that. And jQuery I'm calling before either of those because this
06:28version of photoswipe does depend on jQuery.
06:30All right, I'm going to go ahead and save that, and I can collapse this panel down now.
06:34The last thing I have to do here is instantiate a new photoswipe gallery, and just to remind
06:38you of kind of the structure that we're using here, remember that we have this unordered list.
06:43It has an id of photoGallery. And then each one of the links inside of that is targeting
06:48the larger photo and has the title that can be used as a caption.
06:53So that's the only structure that we really needed to have based on the photoswipe; that's
06:59what it's looking for is those links.
07:01Now I already have a document ready function, and inside that I'm using the lettering method
07:06on one of our titles up there, and that's allowing me to create that really cool
07:10typographic effect that you see up top.
07:12So I'm just going to go ahead and use that and instantiate our photoswipe gallery from there.
07:17So to do this, I just need to establish a new one,
07:20so I'm going to do var myPhotoSwipe, and that could be any name you want it to be.
07:26I think myPhotoSwipe is just fairly descriptive.
07:28I'm going to say equals, and now we have to tell it which element on the page to target
07:33to build the gallery out of. And I'm going to say go inside photoGallery and find the
07:38links inside of that, so that's what I'm targeting.
07:41I'm saying, go find the element up there that has an id of photoGallery and target the links
07:45inside of that and then we just use the photoswipe method, photoSwipe.
07:51What's interesting about the photoswipe method is there are a lot of parameters that we can
07:54pass into that constructor function. We can do things like mouse-wheel scrolling and
07:59whether we want the keyboard enabled or not, whether we want the images to go full screen,
08:04whether we want the photo slideshow to play automatically.
08:06There's so much stuff we can do. It's really cool!
08:08But we're just going to do the default, okay. And to do that, we just go ahead and leave
08:12the array of parameters empty and then type in a semicolon, and that's it.
08:16So if I save this now and then preview this in my browser, and if I scroll down and grab
08:22one of the images and I click, there is our photo gallery, working just wonderfully.
08:28If I resize it, it scales right along with it.
08:31It's very responsive, and if I were on touch screen devices, the touch would be enabled as well.
08:36So I really love that photoswipe gallery. That's very nice.
08:40The other thing that I want to point out about it, before we move on, is how little of the
08:45gallery is actually being controlled by the photo swipe JavaScript. Really, the images
08:50on the page, how they're styled, how they react to the layout, how we display the captions,
08:55that's all up to us.
08:56We did all that using just HTML and CSS, and then the photoswipe gallery just adds that
09:00nice bit of functionality on top of that, which I really, really love about it.
09:04Just remember that anytime that you are integrating an outside library or asset like photoswipe
09:09into your projects, you really have to be mindful of how the asset package is put together
09:14and what all of those dependencies are, what it really needs in order to function.
09:18So make sure you spend a good bit of time deconstructing how something like this works,
09:23so that you'll know what to modify to make it fit into your site's organization and what
09:28your capabilities are, in terms of modifying it the way that you see fit.
Collapse this transcript
5. Enhancing Sites for Mobile
HTML5 form inputs
00:00In this chapter we are going to take a look at a couple of the ways that you can enhance
00:03your site's experience for mobile users.
00:06Most web designers are quite comfortably designing for desktop devices, so much so that we probably
00:11simply take for granted the context that we are designing for.
00:16Because of that, a fair part of learning responsive design is also learning how to enhance the
00:21user experience on devices like smartphones and tablets. The good news is that most of
00:26the things that you can do don't really require a lot of extra work, and many are the result
00:30of simple using the latest web standards.
00:33Take forms for example. By simply using some of the newer input types and attributes found
00:38in HTML5, we can improve our site's performance on mobile devices.
00:42Let me show you what I mean.
00:44I have the contact.htm file open in the 05_01 directory.
00:49Now, before I start working on this, I am going to preview this on a mobile device.
00:54In previewing this page on a mobile device, let's say I scroll down to where the forms are.
00:59So, if I click inside the form element, of course the keyboard comes up and allows me
01:03to type in name, email, things like that.
01:06Well, notice when I hit Next and go to email, nothing really happens with the keyboard.
01:10It doesn't change, because there is no contextual awareness about what is that I am really looking at.
01:15The reason for this is because there's nothing really happening here, in terms of some of
01:19the newer HTML5 form attributes that smartphones just sort of inherently understand and know how to react to.
01:27So, let's take a look at how we do that. All right!
01:29So I am going to go into my form here, my contact form. The first thing I want to do
01:33is find the email form element. It's an input. Right now it's type=text.
01:38What I am going to do is I am going to change that type from text to the new HTML5 type of the email.
01:43The next thing I am going to do is I am going to put up some placeholder text inside that.
01:46So, I am going to use the placeholder attribute, and I am going to say "valid email." Placeholder
01:55attributes aren't just for emails.
01:55I am just going to do placeholder, and I am going to type in "your full name."
02:01That way they give us their whole name and not just their first name.
02:04You know there are also things that we can do like required. It's a Boolean attribute
02:09and basically, what this does is it triggers native form validation.
02:14I'll be honest with you.
02:15I haven't really seen a really good implementation of it yet, and most people are still handling
02:20form validation through server-side or client-side scripts.
02:23So, I'm just showing that.
02:25The next thing I want to do is "website." Instead of the type being "text" that's going to be
02:30"url." So we have a lot of different new input types that we can use. I'm also going to
02:34put some placeholder text here, and I'll just say "website."
02:40There's another form element that I want to change as well, and it's not actually in this form.
02:44I am going to scroll down to the bottom of the page, and I can see that I have a search field down there.
02:50Again, instead of "text," this time I am going to change it to "search," and I'm also going
02:56to put some placeholder data in there as well.
02:58So, let's do placeholder, and inside that I am just going to type in Search, or you can
03:03type in "what you are looking for?" or "what can help you find?" that sort of thing.
03:08So I am going to go ahead and save that, and I'm going to preview this again in my phone.
03:12So now, if I go scroll down to my form, you can see that right there, we have the placeholder
03:18information that we placed in.
03:19So, right off the bat, we're being a little bit nicer to our users, but watch happens
03:23when I click inside these now.
03:24When I click inside the first one, Name, it's still text, so we don't really see any difference.
03:28But when I hit Next, check out the keyboard. The keyboard changed and it gave me the @ symbol,
03:32because it realizes that this is an email address, and that's probably a character that
03:36you are going to use a good bit.
03:38Same thing for my URL.
03:39If I click in that, the keyboard changes again. I get the forward slash with the dot and the
03:43.com, which is really nice.
03:45Now, if I hit Done and I go all the way down to my Search, notice that by changing it to
03:50Search input, when I click inside that, the keyboard changes as well, and we have a nice
03:55little search button down there in the lower right-hand corner when we are going to look
03:58for something. That is a much better user experience.
04:02And although it is a better experience, it's really only scratching the surface in terms
04:06of some of the new HTML5 form elements.
04:09There are things like date pickers, slider, and numeric steppers that are really gaining
04:14support from devices like smartphones and tablets.
04:18It's also worth noting that in many ways, mobile devices are actually early adopters of these new standards,
04:23so, be sure to check support before using them so that you can provide fallback to
04:27nonsupporting devices and browsers.
Collapse this transcript
Adding phone functionality
00:00Often we focus so much on the amazing browsing capabilities of smartphones that we forget
00:06that at their core, they're phones.
00:09As such, we can enhance contact information by easily formatting phone numbers to trigger
00:12calls when selected.
00:14So I'm going to be working in the contact file again, this time from the 05_02 directory.
00:20And the first thing I'm going to do is find the phone number for our website. Here it is, line 37 or so.
00:29And what I'm going to do here is I'm just going to wrap the existing phone number in an anchor tag.
00:35I'm going to do an href here. Now the href for this is actually going to have the telephone
00:40scheme in it, so it's tel and then a colon and then the phone number you want.
00:46Now you could do like a +1 for the United States, or if you knew the country you were in,
00:50you could add that as well. A lot of people really recommend doing that.
00:53I, on the other hand, I'm just going to put the number in 888555, because it's not a real
00:58number, and then 1234.
01:00It's not a bad idea for accessibility to give it a title I'm going to be a bit of smart
01:05alec and go ring, ring, ring, since it is a phone.
01:09And then for class, I'm going to give it a phone. The only reason I'm doing that is for styling.
01:14So again, we're taking our phone number and we're wrapping it in an anchor tag.
01:17We're using the tel schema to format it as a telephone number.
01:21I don't need any dashes, although you can certainly put them in there.
01:24And you could put the international code before it, as I mentioned.
01:26We're giving it a title, for accessibility's sake, and then I'm giving it a class for styling sake.
01:31Now in terms of styling let's talk about that for a moment.
01:34This is a link which means that if somebody hovers over this in the browser, they're going
01:38to see a link that they can click.
01:40Now there are ways to trigger things like Skype calls using a protocol called call to.
01:45But this is just a telephone number, so I really don't want people in the browser to
01:49know that they could click on it.
01:51On the other hand however, inside a phone, now I want it to be really obvious that yes,
01:56this is my telephone number and yes, I'm clickable, please click me.
02:01So we're going to go into our styles and work on that.
02:04So I'm going to switch over to main.css. You can find that in the _css directory.
02:09And I'm going to scroll down into my global styles, about line 128.
02:14So right above the HTML tag, I'm going to add a couple of selectors here.
02:19So I'm just going to do a.phone so I'm targeting any anchor tag with a class of phone applied it.
02:26I'm just going to say border:none, color:inherit.
02:33So what that's going to do for me is it's going to strip out any default border styling
02:37that I've placed on my links,
02:39and it's going to assign the color to whatever the parent element's color is and get rid
02:42of any of that default link styling.
02:45The next thing I'm going to do is I'm going to style a hover for that one as well, so
02:49a.phone hover. And inside that, I'm going to do a border of none. That might look familiar.
02:57I'm going to do a color of inherent.
03:00And I'm going to take the cursor and change that to the default cursor instead of the pointer.
03:05So essentially, what I'm doing is I'm making the hover look exactly the same as the nonhover.
03:11What that's going to do it's just going to have the effect of kind of hiding the fact
03:14that this is a link.
03:15So as a matter of fact, if I save this and preview this in my browser,
03:20you can see that as I hover over this, there's really no indicator that it's a link. So far so good.
03:27The next thing I need to do is style it for the phone itself.
03:30I'm going to scroll down in my mobile styles, somewhere around the 400s. There they are.
03:37And I'm going to find the styles that are covering my form's page.
03:43And so I'm looking of those contact styles. There they are. They're right above the connect styles
03:47where I want to start, and for this one I'm going to save you and me a lot of typing and any typos.
03:54What I want you to do is go check out the _assets folder in the 05_02 directory.
04:01You're going to find the phone.txt file.
04:03And in there, you're going to find this selector.
04:06So if you remember from earlier when I was talking data URIs, I want a icon for my phone,
04:12but again, I really don't want to make another image request to do that.
04:14So this is a perfect example of when a data URI is appropriate.
04:19And again, we're just reducing the amount of HTTP requests, which, over a phone connection,
04:23is a really big deal.
04:24So I'm going to highlight all that and copy it, and then right there, about line 635 or so,
04:30I'm just going to can paste it in.
04:31So what are we doing? We're adding a little bit of padding all the way around this; we're
04:35giving it a background image, which is going to be that phone icon; we're putting a solid
04:39border all way around it; we're giving it some margins top and bottom; we're giving
04:44it a width of 200 pixels so we're making it big enough for people to see; and we're displaying
04:47it as a block-level element so that occupies its own space.
04:51The last thing I'm going to do is apply a little bit of a hover styling to this.
04:55Now, I know most phones don't have hovers, but there are phones out there like the BlackBerry
05:00that allow you do a pointer, and touch events will trigger hovers as well.
05:04So for this one I'm just going to do a border of 1 pixel solid, and the color for this one
05:09is going to RGB 123, 121, 143, so that sort of bluish color.
05:17So I'm going to save this. Instead of previewing that in my browser I need to preview that on my phone.
05:24If I scroll down a little bit, I can see the phone number, and now it's a lot more prominent
05:30than it was on the desktop version of this.
05:32We've got the border all the way around it, we've got the nice phone icon that we've placed
05:35in there, the number is nice and bold, and if I click it, notice that my phone is like,
05:40do you really want to call it a number, because it's not a real number.
05:42As a matter of fact, if click and hold this down, notice that it says, hey do you want
05:46to add that to your contacts?
05:47There's all sorts of really cool things that phones know what to do with phone numbers,
05:51so take advantage of that.
05:54Also, be sure to explore some of the other link formats that you can use as well, such
05:58as the SMS format that allows you to send text messages.
06:02And there are link formats out there that can launch services like the app stores.
06:07Giving your users a convenient way to take advantage of the capabilities of their
06:11device is a simple but powerful way to improve their overall experience.
Collapse this transcript
Adding home screen icons
00:00If you've designed a website or two, you've probably created a favorite icon--
00:04you know, that tiny, little icon that displays in the address bar when somebody visits your site.
00:08Well, for mobile devices we can actually go one better and create icons that will display
00:13on the phone's homepage or home screen and allow people to launch your site the same
00:18way that they launch apps.
00:20So to do that, I'm actually--first here in Photoshop--just to kind of show you what you need to
00:25create to cover all of your bases here,
00:28I've got four pngs that I've created. Very simple logos with the desolve logo on it on a gray background.
00:35The first one is named apple-touch-icon- precomposed.png, and this is a 57x57 pixel icon.
00:45I have the apple-touch-icon-72x72.png.
00:47You see this is just a larger version, 72x72.
00:52I've the apple-touch-icon-114x114.png.
00:57And of course I have the 144x144.
01:01And these are going to be used on different displays,
01:03so the older iPhones are going to use the smaller icons; the larger iPads with the retina
01:08displays are going to use the bigger ones and then sort of scaling down for the retina displays.
01:12And also, the Android devices, one of the nice things about the Android devices is rather
01:17than having their own standard, they just go ahead and accept the Apple ones as well.
01:22So there is a couple that you want to make sure you have in there.
01:25Now I'm going to show how to do the code for this, so I'm going to switch back to my code editor.
01:30And we're going to be working on the index.htm file from the 05_03 directory.
01:37What I'm going to do is, just after meta viewport tag, I'm going to create an empty line.
01:42And although I'm going to paste a code in here, I'm going to go in one line at a time just
01:45so, you don't have to see me typing all of this in.
01:49So the first line should seem familiar to anybody that's worked on websites for a while,
01:53but this is a link that's going out to favicon.
01:57That's a little icon file that's going to appear up in the address bar of the browser,
02:00so nothing new there.
02:02So let's start right here, on the next line below that.
02:06So we've got a comment.
02:08I actually put these comments in all of mine, just so I remind myself what size this is and what it's for.
02:14The first one, the 57x57 PNG file, that's for older iPhone and Android devices.
02:19Notice that I'm using the apple-touch-icon- precomposed relationship, so the rel attribute will be
02:26apple-touch-icon-precomposed. It has to have the dashes in it.
02:29It has to be spelled this way.
02:31Now, you don't have to do precomposed.
02:33If you don't do precomposed, what the iPhone will do is it'll put the glossy finish on it.
02:39You'll notice for the rest of them I don't use precomposed, so why do I use it for the first one?
02:43Well, older Android devices only used precomposed, so that's why that first one has to be precomposed
02:49from me, whether I want it to be or not. And then for the href you're going to point to where it goes.
02:55Now, I'm showing you this as a local testing thing. For your own deployment, one of the
03:02things that I've found, almost 90% of the time, you're going to want the entire path to this.
03:08You're going to what that to be an absolute link.
03:10So you would probably want to just put in, you know, http://www.desolve.org/. So you would
03:17want to put in the entire path to that for your website.
03:21Right now I'm just showing you're a relative link pointing to the image, but when you deploy
03:25that to your site, my advice to you is to go ahead and put in the entire path.
03:31The second icon is the 72 x 72, and I'm doing them in order for a reason. The phone is going
03:36to browse to them and find the one that it wants or the tablet is going to find the one
03:40that it wants and it's going to apply them.
03:42But I want to put them in this order so that the largest newest ones are the last ones
03:46that they run into.
03:48The next one is for the iPad 1 and 2, older-generation iPads, and also the iPad mini,
03:54which is the non retina screen.
03:55That's going to use the 72x72. Notice that I'm doing the apple-touch-icon, so you're
04:01doing apple-touch-icon-precomposed or apple-touch-icon for the rel attribute.
04:05However, for the href you need the size of this in the title of the PNG file.
04:13The next one is for the iPhone 4 the 4s, the 5, and the iPod touch as well.
04:18Those are the first-generation retina screens,
04:21and they're going to use the 114x114. Again, notice no difference in the rel attribute,
04:27but the name of the file is markedly different using the size. And then finally, for the third
04:31generation iPad, you're going to use the 144x144.
04:36So if I save this and I deploy this out to my server,
04:39now I'm going to show you an example of this on the phone.
04:43So if a user is browsing your site and they are like, wow,
04:45this site is so awesome I wish I could come back to it all the time,
04:49all they have to do is click on the phone--and different phones have their ways of doing this.
04:53Right here I've an option that says, Add to Home Screen. You'll notice its already picking on that icon.
04:57And because I'm not using the precomposed, its putting the nice little apple gloss thing to it.
05:02Notice also that I didn't have to the rounded coroners. The device is doing that for me.
05:05So I'm just going to go ahead and click on that.
05:07It uses the title of your page by the way. But I'll just say desolve. And as soon as I hit
05:14Add, you can see right there on my home screen,
05:16there is the desolve icon, and if click on that, it opens up right up again. Awesome!
05:23Now, while this technique does require you to put a fair amount of this proprietary code
05:28that you're seeing here on your page,
05:29it does allow you to have more visual control over how your site is represented on mobile
05:34devices if your users decide to create a shortcut to your site.
Collapse this transcript
6. Managing Resources
Modernizr and Respond.js overview
00:00It would be lovely if we can handle everything necessary for responsive sites with just HTML and CSS.
00:06But, you know, in reality the incredible diversity of all those browsers, devices, and screen
00:12size, and their capabilities means that often we have to turn to JavaScript to help us create
00:17consistent experiences across multiple devices, and there's nothing wrong with that.
00:22But in this movie I want to give you a quick overview of two JavaScript libraries that
00:26are absolutely, in my opinion, crucial pieces of many responsive sites, and that would be
00:31Modernizr and Respond.JS.
00:34So, let's take a look at Modernizr first.
00:36Modernizr, as you can see, they say front end development done right.
00:39So, why use Modernizr? What is Modernizr?
00:42Well, it is a JavaScript library that helps detect a lot of different features, almost
00:47of all the new features of HTML and CSS3.
00:50So, what it will do is it will check your user agent and say, okay, do you support the
00:54following features?
00:56And if it does support the following features, you can do a lot of cool stuff with it.
00:59I am going to scroll down just for a minute here. And you can see right down here where
01:02it talks about how it works, as it's loading, it's going to check for all these different
01:07features and if it finds them, it's going too appended to the HTML element a class for that.
01:12So, let's say if it supports border radius, it will put up a class of border radius on there.
01:16That's means when you are writing your CSS, it's really, really simple.
01:19If border radius is supported, you can just use the border radius class and everything will just work.
01:24If the border radius isn't supported, then those classes won't be applied. And that's
01:28really kind of how it started out, but it has grown into much, much more than that.
01:33So if I go to the full documentation, there is lot of information about what is and all
01:37the features that can be detected.
01:39I just want to browse through those really quickly.
01:42So, here are some of features that are detected by Modernizr. Notice you can see @font-face,
01:47background-size, border_size, image, flexbox, the hsla color values, Multiple Backgrounds,
01:53textshadows, CSS Animations.
01:55I mean there are really--Transforms, Transitions-- and when you start getting into HTML features,
02:00you are talking about some of the new APIs, like Canvas, Drag and Drop, whether that's
02:04supported or not, HTML5 Audio.
02:06So, it allows you to create fallbacks for these things when they are not supported,
02:10Also HTML5 Video, the Web Workers, Geolocation API, SVG, Touch Events, which is huge for responsive sites.
02:18So, you can use Modernizr to detect whether touch events are found, and if so, you can
02:23do whatever you want to do with them, or if they are not, then you can create fallback
02:27events for them, or you can just know that you're not on a touch device and you can
02:30handle something a little bit differently.
02:32We actually did that a little earlier without using Modernizr. Modernizr would have made
02:35that much, much easier.
02:38Modernizr is also extensible, meaning you can go ahead and put your own tests in it,
02:42so you can detect for things that aren't even in the library right now, which is really, really neat.
02:46But perhaps one of the biggest reasons to use Modernizr, and one of my favorite things
02:50about it--I am just going to scroll back--is the fact that it also includes what's known
02:54as the YepNope.js library for loading.
02:57So, essentially it has a script loader built into it, and what's really special about the
03:01YepNope script loader--we are going to actually work with this in just a little bit--is it
03:05allows you to test for certain features and then load resources based on that.
03:10So, we can conditionally load resources, and we can also asynchronously load those resources,
03:16which is just a nice fancy way for saying we are going to load them all at the same
03:19time. And that speeds up your page loading, and it prevents that sort of rendering blockage
03:24that a lot of sites do when they're loading in all their external resources.
03:28Modernizr is just chalk-full of goodness, and what's even cooler about it is that when
03:33you downloaded it you can download a development version of it, which you can kind of go in
03:37there and tinker around with it and do what you want. Or if there's a production one,
03:41click Production--and I am just going to show you this.
03:44You can go in and do your own custom download.
03:46If you don't need everything, then you don't have to have everything, which means you can
03:50make Modernizr just as small as you want it.
03:52So, you can add in these extras.
03:55If you are not going to use the loader, you can take the loader out.
03:57You can test for the Geolocation API, or if you know you are not going to use it, you can leave it out.
04:01So, you can toggle all these things on and off and generate your own custom download
04:06of it, which is really, really nice.
04:09Now, the next library I wanted to show you was Scott Jehl's respond.js. And you've probably
04:14heard me mention him before if you've watched some of my titles. Scott is with the Filament
04:18Group, and they just do some amazing stuff.
04:22They just make the web a better place.
04:24And what respond.js does is it takes a look at older versions of Internet Explorer that
04:29does not support media queries, and it makes it support media queries.
04:32So, by combining Modernizr with Respond.JS, we can test for media queries, whether they
04:38exist or not, and then we can load this up as a poly fill, if they don't exist, which
04:42is really, really nice.
04:43Now Respond used to be built into Modernizr, so if you've heard somebody say, well, respond
04:47is part of Modernizr,
04:48it used to be, but it's not anymore.
04:50So, if we want to use it, we still have to use them separately.
04:52So, for this project I went ahead and downloaded both of these and they're in our exercise files.
04:57If you want to experiment with downloading them, you can, or if you are watching this video
05:01a good bit later than I have done it here, and Moderizr puts that updates quit frequently.
05:05So, chances are there's going to be a different version of Moderizr out by the time you watch this.
05:09If you want to download your own copy of it, you can certainly do that.
05:13Honestly, very rarely anymore do I build any site that doesn't use Moderizr and Respond.
05:18I use them all the time.
05:19Now Respond helps me ensure that older versions of Internet Explore are going to support the
05:23media queries that I am doing, and then Modernizr gives me a complete set of tools for building
05:28a modern responsive site, so I recommend both of them highly.
Collapse this transcript
Loading resources with Modernizr
00:00While Modernizr is fantastic for detecting capabilities and then allowing you to create
00:05fallback experiences,
00:06it also really excels as a resource loader.
00:09Modernizr comes with the yepnope.js loader built right in, so you have an amazing amount
00:15of control over how external resources load, what happens after they load, and then providing
00:19fallbacks for what happens when content doesn't load.
00:23Best of all, Modernizr can load resources asynchronously, which can dramatically speed up page loads.
00:28Okay, so for this exercise, we're going to be doing a lot here, guys.
00:31Go in the 06_02 directory, and you want to open up index.htm, contact.htm, and philadelphia.htm.
00:38Go ahead and open all those up.
00:40Right now, they have been stripped of all their resources, which is terrible.
00:43So all that stuff that we were doing before, where we down towards the footer and loading
00:47up all these external scripts, we have done away with all of that.
00:50Now what that means is, right now nothing is working.
00:53Our gallery is not working; our dropdown menus are not working; our archive galleries menu
00:59isn't being converted over to a select menu.
01:01All that stuff that we've worked so hard on up to this point in our course no longer work.
01:05Okay, now the reason for that is because we really want to do this in an efficient way,
01:10and we want to have a lot of control over when and how resources load, and that's what
01:13Modernizr is going to help us do.
01:15So what I am going to do is I am going to start on the index page, and I am just going
01:17to create a line here between the footer and the body, okay.
01:22So I'm going to create a script tag.
01:23First, I am going to load up my Modernizr file.
01:26Now in this exercise, in _scripts directory, we've added the customized build I did for
01:32modernizr and respond.js.
01:34Now, I have changed the title or the name of the Modernizr download, so if you download
01:39your own and you want to change the name to make it a little bit easier to type in, you
01:43can certainly do that.
01:44So, the source for this is going to be _scripts/modernizr.
01:50It takes a while for you to learn how to spell Modernizr--it's just the way they did it--.custom.js.
01:56And I probably should have copied and paste that.
01:58I know that's going to come back and bite me later on.
02:00I'll close the script tag.
02:01So, that is one thing that we have to do. We do have to load up the Modernizr library obviously
02:05before we can start using the resource loader built into it.
02:09But after that, now we can do everything using the yepnope loader. All right!
02:13So I am going to do another opening script tag and then close it, and I am going to scroll down a little bit.
02:18And then I am going to give myself some space.
02:19If you guys have never used a loader script before, the syntax may be a little odd here.
02:23So just bear with me, and I am going to walk you through it.
02:25I am going to type in a comment here.
02:27This is actually going to help me explain what's going on or what the Modernizr script is doing.
02:31I am going to say use the Modernizr loader to load up external scripts.
02:44This will load the scripts asynchronously, but the order listed matters.
02:54All right, so what this means is, we're going to pass an array of scripts that we want to load.
02:58It's going to load them all in parallel, okay, so they are going to load at the same time.
03:02It's not going to wait for one to finish load and then load the other one.
03:05So, that is good because that's quick, but it's also dangerous because that means that
03:09you could have one library that's dependent on another one and the dependent library, if
03:14it finishes after the other one and then that one calls it and it's not there.
03:17So, this is why the order that it loads in matters.
03:20Although it will load all scripts in parallel, it will execute them in the order listed.
03:35So that's what's important about the order.
03:37It's going to load them up in parallel, but it won't start executing them until they all
03:40load, and it's going to load them in the order that we list them into the array.
03:44Let's get into loading this up. So I am just going to type in the Modernizr.load, and then
03:51what I am going to do is I am going to open a parenthesis and then I am going to do a
03:55square brace, or bracket.
03:57I don't know, whatever it's called. And then down towards the end, again I am a big fan
04:01of closing the stuff before I start doing something else.
04:05I am going to close that, type in a semicolon.
04:07All right, so there is our Modernizr loader object.
04:10One of the nice things about this loader object is we can pass in several different loading
04:14requests, and we do that by using these curly braces.
04:17So I am going to open up a curly brace, and then I'm going to come down here and close
04:22a curly brace, just like that.
04:24Now there are multiple ways to use loader syntax.
04:27One is you can do them all individually. You can just do a load, call, and then point to
04:31the resource you want and then type in a comma, and you can just do this comma-separated list.
04:36I actually like using this method of passing in an array.
04:40To me it seems like it's a little bit more efficient.
04:42You can do it all on a single line, but I am going to do it on multiple lines, just so
04:46it's a little easier for us to read.
04:47So I am going to type in load and then a colon, and then I am going to open up a square bracket
04:54and then close the square bracket.
04:56Let me tab and indent this so I could read this a little bit better.
05:00Now each of these can go on their own line, and I just have to pass in who I want to load up.
05:04And first one is going to be http://ajax. googleapis.com/ajax/lib/jquery/1.9.0/jquery.min.js.
05:32And yes, I probably should have copied and pasted that from somewhere. And also remember,
05:37in deployment, if I am not testing this locally, I would leave off the protocol.
05:42Now, we separate these with a comma, so this is a comma-separated list.
05:45I am going to go down to the next line and I am going to load in my desolve scripts.
05:49So I am just going to point to my scripts folder /deslove.js, then another single quotation
05:56mark there as well.
05:57So you can string as many of these in as you want.
06:00I really only need these two right now.
06:02So I'm going to save this, test this in my browser.
06:10Now, my menus are working, but this version of the menu doesn't use JavaScript anyway, but
06:14I am going to resize my page, and when I do that, I can see I'm getting my dropdown menu.
06:21My dropdown menu here is looking good.
06:23I am not looking at the default. And my dropdown here is working good.
06:27So all of my JavaScript libraries are loading again.
06:30They are loading in the way that I want them to, and they are loading in right currently
06:34asynchronously, okay.
06:35I'm going to highlight this, copy it, and then paste it in each of these pages, just below
06:43the footer, but before the closing body tag.
06:46I'm going to save the contact, and then I am going to do this on the Philadelphia one.
06:50Now, here is one of the beauties of using this loader this way.
06:55Because Philadelphia has the photo gallery, it needs more resources than the other ones do.
07:00Well, that's okay. I can just put as many resources into this loader object as I need to.
07:06so what I am going to do is I am just going to create a couple of blank lines here above the desolve.js.
07:11Remember, I am doing them in the order that I want them to execute. So, this one is going
07:14to be _scripts/klass.min.js.
07:20Now, don't forget the comma between these guys.
07:25Then the next one is going to be _scripts/code.photoswipe. jquery-3.0.5.js. And yes, it would have been better had I copied and
07:43pasted it. And then don't forget your comma.
07:45All right, so in addition to what we were loading up in our other pages, now I am also
07:50loading up my klass library and my photoswipe library, and I'm listing them in the order
07:55that I want them to execute.
07:57They will all load in parallel, but I want to list them in the order that I want them to execute.
08:01Okay, that's great, but how do we instantiate our photoswipe library? How do we do that?
08:05How do we make that call?
08:06Well, I don't have to write separate functions anymore.
08:09I can just call right directly from the loader object.
08:12So as soon as this is done loading, you can call anything that you want.
08:15So right after my loader object, right after that square little closing brace there, I
08:20am going to add a comma. Then I am going to go down on the next line, and now I am going
08:25to type in complete.
08:27So there are a couple of things that you can do. You can use callback functions or you
08:30can use a complete.
08:31Now the complete basically is going to say hey, when those guys have executed, when they've
08:36all executed, now do this.
08:38And I can just go ahead and do function, and then inside that function I can just go ahead
08:45and instantiate my photo gallery.
08:47So just the same way we did before, var. As a matter of fact, if you don't feel like typing
08:51it, you can simply copy and paste it.
08:53myPhotoSwipe =. And then if you remember, we were targeting the photoGallery a, and then
09:05we're going to do just the generic photoSwipe instantiation.
09:10And now, if I save this and test the Philadelphia page, not only are the menus working, but
09:21if I click the gallery, the gallery is now working as well, so it's bringing in those
09:25resources and I am firing a complete function to instantiate the photo gallery as soon as
09:30they've finished loading.
09:32And you know, if we really only needed to load just these assets, using a loader like Modernizr
09:37really wouldn't make a whole lot of sense.
09:39You know, it's one of those if you have a hammer, everything starts little like a nail type deal.
09:43We're not really gaining that much speed by using these guys in parallel. Most browsers,
09:47as a matter of fact, will start to load things in parallel now by default.
09:51So we could just load them up using normal script tags if we want and let the browser
09:54handle loading and we wouldn't really notice that big of a difference.
09:57But if we had a lot of external resources, we'd see better performance enhancements based
10:01on this asynchronous loading. And using Modernizr as a loader has other benefits as well, as
10:07we're going to see in our next exercise.
Collapse this transcript
Conditional resource loading
00:00Where Modernizr really shines as a loader is in its power to conditionally load assets--
00:05that is, loading resources when certain conditions have been met.
00:09In this exercise, we are going to see how conditional resource loading allows us to
00:12test for things like media query support and screen size and then load in the necessary resources.
00:18So I am working from the 06_03 directory.
00:22Once again I have got the index, contact, and Philadelphia.htm files open. We're really picking
00:26up right where we left off,
00:28so if you want to leave your old ones open, that is just fine.
00:30Now, I want to point something out to you guys. Right now--if I scroll up to the top of the
00:36page--I have a conditional comment at the top of the page that targets Internet Explorer,
00:43and it loads respond.min.js in case it happens to detect Internet Explorer lower than version 9.
00:52That's actually really common.
00:53I have seen that a lot, and what that'll do for you is these conditional comments are
00:58only recognized by Internet Explorer, so other browsers and devices and things will ignore them.
01:03Well, it's nice that it's there, but one of the things that Modernizr does that we can
01:06take advantage of is it allows us to test for features and whether those features are supported or not.
01:11That way we don't even really have to be as generic as saying Internet Explorer 9 or less
01:16than Internet Explorer 9, we can just say, hey if this device doesn't support media queries,
01:21let's try respond.js. All right!
01:23So I am going to delete--I am actually going to get rid of that and then I am going to
01:26scroll down, back down to my loader object. And now, here's where the syntax can get a
01:33little tricky, okay.
01:34The way that I sort of deal with this is that these curly braces represent sort
01:39of distinct discrete calls to the loader object.
01:42And you can have as many of them as you want in here, and you separate them by using commas.
01:47We have already got one going on, and we want to actually do a test.
01:50So what I am going to do is I am going to do a comma and then go down to the next line.
01:55And again, I'm just going to speed up the process a little bit here by pasting some code in,
02:00but I want you to see exactly what I pasted in, so that you guys know what you are adding here.
02:06So, code that I am highlighting is what I'm adding, and you can go ahead and pause the
02:10video and type that in.
02:12Don't forget the comma that's going to separate these two blocks of code, okay?
02:17So what we're doing here, the first comment sort of tells you, we are testing for media query support.
02:22If it's not found, let's load up respond.js.
02:24So what we are doing here is we are saying, hey, test : Modernizr.mq('only all') so we
02:30are just passing an argument in saying, does it support only for media queries?
02:36And if it supports only--you know only is a keyword that basically is just a trigger
02:40that says, hey do you support media queries-- you could pass a full media query into it,
02:44but I really just want to test if it supports media queries at all, not a specific screen size.
02:51These methods that Modernizr has, you can look at the Modernizr documentation and find
02:56all of those, so that mq stands for Media Query.
02:59So basically, it's going to test. Right after that we have a little comma and then we say,
03:02if not, load the response file. This is where yepnope really shines.
03:07We can use either yep or nope, so if we wanted to do something in case it did support them,
03:11then we would use yep.
03:13But this time we only want to do something if they are not supported, so we use nope.
03:17And we just tell it what we want to load up, in this case the '/_scripts/respond.js'.
03:22So this same little section of code here, I am going to copy this, and I am going to
03:27paste this into each of these files. And of course I am going to get rid of the conditional
03:34comment on all of them as well.
03:35So I will type in a comma, paste that, save it.
03:39I am going to go into Philadelphia and do the same thing.
03:42Now, when we get to Philadelphia, we have slightly larger fish to fry, if you will.
03:47Once again, I am going to do the same thing here. We will do a comma at the end of this,
03:51and we will paste it in. All right!
03:54So notice that, again, these are just discrete blocks of code, and you want to use commas to separate them.
04:00All right, so there's another thing going on in the Philadelphia page that you may or
04:05may not have noticed when we tested it last time.
04:07That sort of cool typographic effect up top, it didn't happen.
04:10And the reason it didn't happen is because there is a library that we are loading up
04:14to help us with that and that is lettering.js.
04:16Now, what lettering does for you is you pass a target into it and then it takes every single
04:21character in that particular target element, every letter, and it wraps a span tag around
04:26it, and it gives it a class that you can target. And that way you can do kerning, you can do
04:30special type effects through your CSS, all sorts of things like that.
04:34Now, for this page we are only doing that special type effect at the tablet size and
04:39at the desktop size. We are not doing it at the mobile size, because it's so small that
04:43it could kind of overpower things and it just doesn't look all that great at that small size.
04:48So we are not doing it.
04:48So we actually don't need lettering.js at those sizes.
04:53And what that can do is we can conditionally load whether lettering.js is requested or
04:58not based upon the screen size by using that same media query test.
05:02And what that does for you, if you think about this for a second, is it means that you're
05:06lowering the overhead for mobile devices because it's not requesting resources that it wouldn't use.
05:11So it's a really powerful feature.
05:13All right, so to do this, again I am going to type a comma right after the last block
05:17of code, and then I am going to type in an opening and a closing curly brace, just like that.
05:23Now I am going to enter some more text this time, and let me even the stuff out here, get
05:31my tabs all right. There we go, cool.
05:34So what we're doing here is we are testing to see if it's a bigger screen. So this time
05:38instead of testing to see if it supports media queries just in general, we are testing a
05:42very specific media query. We are saying only all and minimum width the 481 pixels. Again,
05:47that's targeting our mobile devices. We could go to 480 I suppose, but anyway that's the
05:52minimum width that we are targeting.
05:54So after that, if that happens, this time instead of using nope, we are using yep.
05:58This syntax is a little different because when you use yep, or nope for that matter,
06:03you could use a callback function. And what a callback function is, it says okay, if that
06:08evaluated successfully, I want you to do something, and that's what callback allows you to do.
06:12The callback function passes several different objects into it. One of the objects you can
06:17pass into it is a key.
06:18A key is simply just a variable that says, yes, that did happen.
06:21In this case I am naming the key bigscreen because it's kind of descriptive.
06:26So we are defining a key and then we are telling it which resource to load, so we are saying,
06:30yes, big screen is yes, load this script for me.
06:34Now that means that there's still some code left to right here.
06:37You will notice that we have a nice little comma right after this, so I am going to go
06:41down to the very next line and I am going to enter in the rest of the code.
06:46Now, this gets a little tricky, so make sure that when you're looking at this that you
06:51understand where the opening and closing curly braces and all the functions and everything fall, okay?
06:57I'm trying to make sure that the tabs are okay here, so let me even these out. There we go.
07:04This should all more or less even out.
07:06So what you are looking at here is, after loading lettering, we are going to target the gallery
07:10title item on the page with the lettering library. So we are performing a callback function
07:14and we do that by saying callback and then function. The parameters that are being passed
07:19in or URL, the result, and the key, so the result is that it was a success.
07:23And the key of course is going to be this bigscreen variable value that we pass in.
07:28So we can say hey, if the key is equal to big-screen, meaning it was a success, we are
07:33going to do something. We are saying when the document is ready, go ahead and apply
07:36the lettering functions.
07:38So this way we are conditionally applying it conditionally calling that when it's a big screen.
07:43Now, you'll notice that this isn't handling resizing it all.
07:46I could certainly write a resize function in here so that when the screen is resized,
07:51it does it. But one of the things that I'm doing here is I'm only asking and requesting
07:55for this library if the screen is larger than mobile.
07:58So in this case, if somebody resizes it or turns it into a landscape mode and the
08:05lettering doesn't come up, it's not the end of the world, and I've saved that user from
08:09having to download that resource, so they are getting it faster anyway.
08:12So, now if I save this, I am going to go ahead and preview this up in my browser. There we go.
08:20And you can see now the lettering effect is happening.
08:22Now, I'm going to resize this down, refresh, and the resource is not loaded, which is fantastic.
08:30Now, I know that went on for a little while, but I have seriously just barely scratched
08:34the surface of what Modernizr can do.
08:36If you want a more complete look at using Modernizr and especially using it to load resources,
08:41go ahead and check out the documentation on Modernizr's website as well as going to the
08:45home page for the yepnope JavaScript library. So be sure to check out yepnope.js because
08:51they have a lot more documentation about conditional resource loading and the asynchronous loading as well.
08:55
Collapse this transcript
Testing responsive sites
00:00Testing responsive sites is a bit tricky, I've got to be honest with you.
00:05Although you can certainly test them locally, figuring out how your site is going to perform
00:09on mobile devices can be incredibly frustrating.
00:13You could download and install a few mobile emulators, but while they will give you a
00:17decent idea of how your site is going to perform, they're really not 100% reliable and very
00:22difficult to debug, to be quite honest with you.
00:25I recommend checking out a couple of resources here.
00:28The first one is weinre, although some people are fond of pronouncing it weiner.
00:33weinre actually stands for WebKit Inspector Remote, or WebKit Remote Inspector, or I don't know whatever.
00:40But what it does is it allows you to remotely debug and test sites on mobile devices from your desktop.
00:44So essentially, you'll browse to the site on your phone or your tablet and then you'll
00:49use your desktop browser to run WebKit Inspector, so it's really cool.
00:54You can also download this and install it locally and then connect all your mobile devices
00:58through Chrome or any WebKit browser.
01:01Now, this does require a little bit of technical expertise to set up.
01:05I'm going to be honest with you.
01:06If doing this on your own isn't really for you,
01:09it is bundled into PhoneGap's service, so if you're working with PhoneGap, you'll be able
01:14to use it as well. And it's also bundled inside of Adobe's Edge Inspect, which is Adobe's
01:19new remote debugging and testing service for mobile devices. And I love Edge Inspector.
01:25I talked about it a little bit earlier in the title.
01:27I am a big fan of it.
01:29It's available with a membership in Creative Cloud and you can go try it out,
01:33if you're not sold on it right off the bat.
01:35But what it allows you to do, basically, is not only do the remote debugging that
01:39weinre allows you to do, but let's say you're working locally. You can sync a ton of devices
01:44up to it. As you save something locally, it will push updates to all of your remote devices,
01:49so you can kind of see your changes real time on multiple screens and multiple devices all around you.
01:53So, a very, very handy piece of software in terms of testing your performance and developing.
01:58Now the last thing I want to show you is Mobitest.
02:01This was formally run by blaze I/O, but I think they were acquired by Akamai, so it's on their site now.
02:08So if you just do a search for Mobitest, this will come up.
02:10Now, what's cool about Mobitest is you have to have a hosted site, but then you type in
02:14the URL, and it'll run a test and you can choose what device you want it run it on,
02:20what server you want to use, how many tests you want to run, that sort of thing, and then
02:23what you get back is what you're seeing here.
02:25You get back an Average Page Size--whew, bloated--
02:28a load time, and then it gives you a couple of waterfall charts down here, some screenshots,
02:33which is really cool, and it also gives you an HTTP archive file, which you can download
02:38or you can click to just kind of view it through the software's hard viewer, which is awesome. I love that thing.
02:43And you can open it up, and it shows you your waterfall, so you can see what resources were
02:48requested, when they were requested, how long it took them. You can really see where you
02:52need to do a little bit of work maybe.
02:54This would still have some work on it, in terms of getting it to load as efficient as
02:58I would like it to.
02:59But that's not too bad, I suppose. It's 1.29 seconds. That loads fairly quick.
03:05So it's not 100%. For example, for whatever reason, does keeps reporting to me that it's
03:10actually requesting some of my external scripts twice, although it's not, so it's not
03:16100% accurate, but it does give you nice picture of it. And really what that tells you more
03:20than anything else is you just can't beat testing these on your own devices.
03:25So that is definitely something that if you're committed to doing responsive design, you're
03:29going to have to try to get as many devices as you can and you're going to have to try
03:33to test on those actual devices as thoroughly as possible.
03:37It's just part of the new reality that we have as web designers in dealing with responsive design.
03:41
Collapse this transcript
Conclusion
Additional resources
00:00I hope you've enjoyed Applied Responsive Design, and that you'll take the techniques and strategies
00:04that I've outlined here and delve a little deeper into how they can transform your projects
00:08into responsive sites that take full advantage of the diverse capabilities that all those
00:12user agents have to offer.
00:14Now, before I go, I want to take a quick look at some of the additional resources that I've
00:18compiled for you that can help you learn a little bit more about the concepts that
00:21were presented in this course.
00:22Now, the first section of the Additional resources--and by the way, you can find this file in
00:2707_01 Exercise Files directory as well.
00:31So I've got links to a couple of sites here, to Luke W's site. You've probably heard me talk
00:35about him before. He is a writer of all things mobile and really one of the biggest contributors
00:40out there right now of what it means to design towards mobile devices.
00:44So he is definitely a must-read.
00:47Unstoppable Robot Ninja is the home page of Ethan Marcotte, who is the coiner of the term
00:52responsive design. So I guess you could say he is kind of the granddaddy of it all, and
00:56he is the author of the Responsive Web Design Book that A Book Apart put out.
01:00bradfrostweb.com is the blog of Brad Frost, and he is one of the guys out there that really
01:07writes and focuses a lot on responsive design. As a matter of fact, I've got another one
01:11of his sites that he curates called This is Responsive, a little bit further down the page.
01:16A List Apart, if you are a web designer or web developer, this is an online journal that
01:20you should be reading all the time.
01:22We've also get to a set of Resources down there for you too. The first one was that This is Responsive.
01:28This is great.
01:30This is kind of like, this is what I should have put together for all of your Additional
01:34Resources anyway, so a lot of things that they didn't list on the page, because, well,
01:37they're listed here.
01:38So there's a lot about strategy here, approaches, concepts, processes, different tools, style
01:44guides, different ways to approach layout, media queries.
01:47I mean, what can I say?
01:49This is incredibly comprehensive.
01:50So, and he is adding stuff to it all the time, so this is a site that if you're serious about
01:56responsive design, you're going to want a book like this.
02:00Next we have Touchscreen Stencils. This is one of the places where I've got those
02:05handy-dandy touch icons.
02:07You can download these. They have them from different programs.
02:09They also have some vector ones that you can download. You can print them out.
02:13They've got stencils.
02:14They've got all sorts of really cool stuff here, and they're offering to you for free,
02:18which is just awesome. So this is from Kicker Studio. You want to take a look at those.
02:23We have some GestureIcons. These GestureIcons are some of the most beautiful ones I've seen out there.
02:28These are fantastic!
02:29Now, they are not free, but they are well worth it if you're doing a lot of prototyping. Y
02:33might want to check these out.
02:35We also have an Open Source Gesture Library, and this is actually massive.
02:39When I first started looking into this, I was amazed by all the things that are here.
02:43There are not just icons and vector artwork for you to take a look at too, but there is
02:47actually a markup language that's designed around gestures and that's GML.
02:50So there's a lot going on with this group, and if you're interested in touch and gestures,
02:55which, if you are doing responsive design, you're going to have to deal with that,
02:58this is a website that you want to spend some time on.
03:01We also have the Data URI Generator that I showed you guys earlier.
03:03It's a great way for generating Base 64 Encoding for your images.
03:08We have FitVids.JS. I mentioned that earlier as well. And this is a JavaScript Library
03:14that helps you create responsive video on your page, and can help you out maybe when
03:18some of the techniques that showed you hit a wall or don't quite work with the delivery
03:22system that you're using.
03:24We also have of course as always, lynda.com, the online training library. We have
03:29a ton of courses available for you for web and development.
03:32And if missed out on my Responsive Design Fundamentals course in the lynda.com online
03:36training library, I highly recommend going back and watching it, because it focuses more
03:41on the strategies and concepts behind responsive design.
03:44So it's a nice overview of all that as well.
03:47And finally, on the Additional resources, I have a link to me on Twitter.
03:52If you'd like follow me on Twitter, I am @jameswillweb.
03:55I would love to hear from you. Most the give- and-take I do with subscribers is on Twitter,
04:00so please follow me and join the conversation.
04:03Well, that is all for now folks!
04:05Thanks so much for watching, and I will see you in my next course.
Collapse this transcript


Suggested courses to watch next:

Interaction Design Fundamentals (3h 18m)
David Hogue


Responsive Design Workflows (1h 20m)
Justin Putney


Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 104,069 instructional videos.

get started learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 2,024 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.

preview image of new course page

Try our new course pages

Explore our redesigned course pages, and tell us about your experience.

If you want to switch back to the old view, change your site preferences from the my account menu.

Try the new pages No, thanks

site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

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.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked