navigate site menu

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

Responsive Design with Drupal

Responsive Design with Drupal

with Chaz Chumley

 


In this course, Chaz Chumley takes you through the process of transitioning a Drupal website to a responsive model that automatically tailors and sizes content for a wide range of displays, from desktops to mobile devices.

The course starts with setting up the Drupal environment in Acquia and defines some basic principles of responsive design before moving on to creating a new Drupal theme with fluid layouts, fluid media, and responsive tables and forms. Chaz also covers writing media queries, which allow you to create different style sheets for each device type.

The course wraps up with a look at Respond.js and content-aware image sizing in Drupal—responsive design tools that can optimize your project for maximum performance.
Topics include:
  • What is responsive design?
  • Understanding fixed-width vs. fluid layouts
  • Working with fluid margins and padding
  • Writing a media query
  • Creating responsive menus and forms
  • Adding min- and max-width support with Respond.js

show more

author
Chaz Chumley
subject
Developer, Web, CMS, Blogs, Responsive Design, Web Design, Web Development
software
Drupal 7
level
Intermediate
duration
2h 38m
released
Jan 11, 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:04Hello, I am Chaz Chumley, and I would like to welcome you to Responsive Design with Drupal.
00:09In this course we'll explore exactly what Responsive Design is, why it's important when
00:14creating or modifying websites, the different techniques involved, and how that is applied to Drupal 7.
00:21We will begin by quickly setting up our Drupal environment and installing the fixed-width theme
00:26and then progress to how we make that theme scalable for mobile devices.
00:31Along the way we will take a look at various techniques involved in the mobile workflow,
00:35such as CSS 3 Media Queries, fluid layouts, fluid images, responsive forms, and how to
00:43apply these techniques within the Drupal 7 framework.
00:47So let's get started with Responsive Design with Drupal.
Collapse this transcript
Using the exercise files
00:00In order to better follow along through each chapter of our series, we've provided a set
00:04of exercise files for you to use.
00:07However, keep in mind that if you are not a premium lynda.com subscriber, the contents
00:12of these exercise files may vary. On my Desktop I have the Exercise Files folder.
00:16It is broken into four sections.
00:19The Final folder holds the final source files for our Drupal 7 Responsive Design, and it
00:24is what you're striving toward completing as we finish the series.
00:28The next folder is our HTML folder.
00:30This folder contains a static HTML version of our website in various stages, from fixed
00:35to fluid, and may be referenced at various points in the chapter.
00:40Next is a Lessons folder.
00:41The Lessons folder contains both readme files for everyone as well as a JavaScript or CSS
00:48files that we'll be using throughout the series.
00:49Since we're also dealing with Drupal 7, you may find .info or template files that we'll
00:56be using for theming. The final folder is our Start folder.
01:00The Start folder actually contains the starting Drupal installation and SQL file that we will
01:05use to create multiple instances of Drupal that will represent various techniques with
01:10fixed, adaptive, and responsible websites.
01:13You may have noticed that I've also broken them out into a Drupal folder that will hold
01:18these three instances that we will be utilizing as we progress through each section.
01:23Let's get started.
Collapse this transcript
Exploring the finished project
00:00Someone once said Responsive Design is responsible design, meaning that we cannot just design
00:05for the Desktop browser anymore.
00:07We need to think outside the box and understand how more and more people are viewing websites on mobile devices.
00:13In this video we'll take a look at our finished Drupal 7 Theme and discuss how we moved from
00:17a fixed-width layout to a more fluid one.
00:19Let's begin by looking at the fixed width theme on various screen sizes.
00:23As we resize the browser, we will notice that the content stays fixed or constrained based
00:28on the pixel width measurement at the site that was designed against. Images and content just don't scale.
00:34However, comparing it against our finished theme, we can see that our design now reacts
00:38the various breakpoints, from browser, to tablet, all the way down to mobile.
00:43We have taken a look at both the fixed-width theme and our completed responsive theme
00:47and how mobile workflow needs be considered when creating any website today.
00:52Understanding these concepts and how to best overcome the challenges associated with it
00:56will be covered in more detail later in our series, but first, we must set up our development environment.
Collapse this transcript
1. Setting Up the Environment
Installing Acquia Dev Desktop
00:00To eliminate the confusion between Windows, Mac, and Linux, and to make sure everyone can
00:05follow along easily, I want to introduce you to a platform-independent application by Acquia,
00:11known as the Dev Desktop.
00:13This tool will allow us to quickly set up a local app stack that's Apache, MySQL, and
00:18PHP so that we can easily work with Drupal.
00:22Let's begin my browsing into acquia.com/downloads and choosing the version of Dev Desktop suitable for your environment.
00:30If we scroll down to the Dev Desktop section, we want to make sure that we choose the Drupal 7 Instance
00:35and the platform that best suits you.
00:39In this case, I am going to go ahead and select Mac, and then I'll click on the Download button.
00:43The Dev Desktop is actually the fastest way to Drupal.
00:46This includes the Acquia Drupal stack and allows us to set up new instances.
00:51It allows us to import existing instances and have a self-contained platform that we
00:57can easily do our development on.
00:59Once our download is complete, go ahead and close the download window if you have one
01:03and then go ahead and minimize the browser.
01:05At this point I want to go ahead and locate my Downloads folder and then double-click
01:10on the Acquia Drupal Installer, minimize my Downloads window and then go ahead and double-click
01:15on the Installer to start the installation process.
01:19If you happen to be on a Mac or Windows environment and are prompted with a message, Do You Want to open this File?
01:25By all means, it is safe. Go ahead and click on the Open button.
01:28Also, if you're prompted for your credentials, go ahead and entry those now, Click on OK
01:33and then the installation process will begin. The first screen is the Acquia Welcome Screen.
01:39We want to go ahead and just click Next to begin, go ahead and click Next again on the Overview
01:43screen, and then we are at the License agreement, go ahead and choose Yes and then click on Next.
01:49You're perfectly fine leaving the default installations as is by clicking on Next, and
01:54then go into the Port settings screen.
01:56From here, you may see some non-standard ports being used. That's fine as is because we're dealing
02:02with a self-contained app stack, so I'm going to leave those as is and click on Next.
02:07From here, this is the screen that is asking us for some information regarding the site
02:11name, our username, password, and an email.
02:14Acquia out of the box likes to set up a default Drupal Instance.
02:19We're finally leaving the Site name as is, your Username is going to be whatever your
02:23Username is, for a Password I am going to go ahead and put in admin, all lowercase, and
02:28then go ahead and put an email.
02:29Once I have the information in there for Drupal Settings, go ahead and click Next.
02:34Go ahead and Review your information, everything looks great, click on Next.
02:38From here we're ready to ready to install, go ahead and click on Next, and the installation process will begin.
02:44Once your installer has completed, go ahead and click on the Finish button to launch the Acquia Dev Desktop.
02:50From here we want to go ahead and take a look at that default Drupal Instance that was created
02:55as part of the installation process.
02:57Go ahead and click on the Go to my site button, that will go ahead and open up the browser
03:01window for us and take us to the site.
03:04Go ahead and say hello as well as goodbye to this instance, because this is the last
03:08time we will be using a default Drupal Instance.
03:12At this point, everyone regardless of your respective experience level with web servers
03:16or app stacks that you have already installed prior to this video should be on even plain field.
03:22We reviewed the Acquia Dev Desktop environment,
03:26how to install and configure the default instance, but next we're going to go ahead and take
03:30a look at how easy it is to actually import existing Drupal Instances using the Dev Desktop.
Collapse this transcript
Importing a Drupal website
00:00In most cases you won't be dealing with a default Drupal Instance.
00:04More than likely you already have an existing Drupal site that you're working with.
00:08So let's take a look at exactly how easy it is to import a site using the Acquia Dev Desktop,
00:14and not just one site, but three different instances that we will be using as a basis
00:18for fixed, adaptive, and responsive designs.
00:23Let's begin by creating a Folder on our Desktop called Drupal.
00:26This'll be where our three Drupal Instances will live while we work through the different stages of Responsive Design.
00:31I am going to right-click and say New Folder and give it a name of Drupal, and then next
00:37we actually need to have a Drupal Instance to work with.
00:40So, if we open up the exercise files and locate the Start, drupal, and start.sql files.
00:47Something that I've done is provide both the free and premium subscribers with access to these files.
00:53This way everyone has an even playing field to start with, and we have a basis to build
00:59upon as we progress through each chapter in our series on Responsive Design.
01:04Go ahead and copy the Drupal folder over to the Drupal Desktop and paste it in place.
01:11Since we're going to be working with three different Instances of Drupal, I want to repeat this process real quick.
01:18First, let's go ahead and give this folder name of drupal.fixed and then since I still have
01:24in memory that Drupal Instance, I am going to paste it again.
01:27The second folder, we'll go ahead and call this drupal.adaptive or adaptive design, we'll be working with.
01:34And then I'm going to paste one more time.
01:37Let's go ahead and name third instance, drupal.responsive.
01:42Now that I have the three instances created, go ahead and close the folders, and before
01:47we actually go ahead and start the import process, it's very important to know that
01:51once you've created a folder--especially on the Mac--that you need to make sure that it
01:55has Read-Write permissions for all users and the enclosing files.
02:00So quickly right-click on the Drupal folder, Click on Get Info, and locate the Sharing & Permissions.
02:07You may need to unlock the permissions, we'll do so now, and then change it to Read & Write,
02:14and then Apply to enclosed items.
02:17You'll be prompted, yep, we want to go ahead and do that, so click OK.
02:20And once those privileges have been applied, go ahead and click the Window and then with
02:26the focus back on the Acquia Dev Desktop Control panel, choose Settings.
02:31From here, click on the Site's tab and then only Import button.
02:35We're going to be repeating this process three different times, so it's very important that
02:39we get it right the first time.
02:41By clicking on the Browse button for the site path and then locating the Drupal > drupal.fixed
02:47instance and double-clicking on it, we can set the Site path.
02:50Next, since we already have a database backup, go ahead and click on the Browse button for the
02:56dump file, locate the exercise file's start folder and double-click on start.sql.
03:03Let's give the Database a name, in this case drupal_fixed, and then for the Domain name,
03:09let's go ahead and repeat this, but instead of an underscore, we'll call this drupal.fixed.
03:14This is more in line with URL naming conventions, go ahead and click the Import button, and
03:18if prompted for permissions, go ahead and put in your Username, Password and then click OK.
03:24With our first instances imported, we need to repeat this process two more times.
03:28I'm going to go ahead and let you take care that now, remembering to name both the URL
03:34and the database files appropriately based off the responsive and adaptive instances
03:40that we have inside our Drupal folder.
03:43Importing out of the way, we now have three different Drupal Instances for us to use to modify.
03:48Comparing, as well as add different responsive techniques throughout the chapters.
03:52However, as we work along, you may find yourself needing to back up your work.
03:57So let's move on to see how we can easily use the backup and migrate modules inside
04:02of Drupal, to back up and restore existing Drupal Instances.
Collapse this transcript
Restoring database snapshots with the Backup and Migrate module
00:00Being able to back up and migrate your Drupal site is an important part of the development workflow.
00:06As we progress through each chapter, you may find yourself wanting to back up your work
00:10or restore from one of the many database snapshots that we will be using.
00:14Let's take a moment to discuss how to best work with the database snapshots that are
00:18part of the exercise files provided to premium subscribers.
00:22The Backup Migrate module itself is located at drupal.org/project/backup_migrate, and
00:29it is stable for any Drupal developer needing a consistent mechanism for backing up and
00:35restoring their Drupal sites.
00:37As part of the import of both our fixed, adaptive, and responsive Drupal sites,
00:41I have taken care of the installation and enabling of this module for you.
00:46If you need a refresher on how to download and enable modules, please take a look at the various
00:51Drupal 7 Lessons at lynda.com. So that we can take a look at to configuration for our site,
00:57you will need a first log in to the Drupal Instance we set up earlier.
01:01Go ahead and open up a New Tab and type in the drupal.fixed and import 8082.
01:09You're now getting your first glance at our responsive designed website.
01:13So what we need to do now is sign in to the site.
01:16You can do that by typing /user, and then from the user account, type in the user credentials.
01:23In this case, admin, all lowercase as well as the Password being admin, all lower case.
01:29Go ahead and click on the Login button, and now you're in the backend of our Drupal Instance.
01:34In order to see the Backup Migrate module where it is and how it is configured, we need
01:39to actually navigate to that section of the site.
01:43Under Configuration > System > Backup and Migrate.
01:47We're now on the landing page for Backup and the Migrate.
01:50I'm not going to go into too much detail on the configuration of this module, but focus
01:55more on the backup and the restore.
01:59Right now, the quick backup is set for the default database to download using the default settings.
02:05That's perfectly fine for our needs.
02:07Go ahead and click on the Backup now button and then browse over to our Downloads folder,
02:12and there we can see the database snapshot that was taken.
02:15We're going to go ahead and repeat this process, but in the opposite manner, in this case we're
02:20going to restore from the backup that we just took.
02:24This will be the same process you will be using for the database snapshots found throughout the exercise files.
02:29In this case, go back to the browser and then click on the Restore tab.
02:33From here, go ahead and click on Choose File, locate at the Downloads folder and then the .mysql file.
02:39Go ahead and click on Open and then Restore now button.
02:44Once the Restore is complete, you will get a confirmation from Drupal telling you that
02:48the restore was successful.
02:50We now have a better understanding how the Backup Migrate module can be used to both
02:54take database snapshots, as well as restore database snapshots, as we progress through
03:00our series on Drupal 7 Responsive Design.
03:03Before we dive into the concepts behind Responsive Design, I want to take a look at one more
03:08tool that will help you in developing your themes in Drupal 7.
Collapse this transcript
Understanding the Devel module
00:00If you've been developing or designing in Drupal 7 for any length of time, then you
00:04may have come across a module called Devel.
00:07If not, you may have asked yourself if there was any way to see exactly what variables
00:11Drupal 7 outputs and how to best work with those values.
00:16To make theming easier for us, let's take a look at where to find the Devel Module and
00:20some of the best ways to use this module for our own needs.
00:24The Devel Module is located at drupal.org/project/devel, and is another staple for any Drupal developer
00:31needing a way for debugging their own Drupal sites.
00:34As part of the import of our fixed, adaptive, and responsive Drupal sites, I've taken care
00:40of the installation and enabling of this modules for you. So that we can take a look at the
00:45configuration of our site, you are going to need to first log in to the Drupal Instance we set up.
00:50Go ahead and tab back over to our site or go ahead and bring it up in the browser at
00:54drupal.fixed:8082/user and then go ahead and log in with the admin credentials.
01:02In this case, all lowercase, the word admin, the same for the Password, and then click on the Login button.
01:09With the admin toolbar present, go ahead and navigate to Configuration > Development > Devel Settings.
01:17The Devel Module has numerous configuration settings that assist the Drupal designer or
01:21developer with a lot of information that you may not ever see otherwise.
01:26Such items as Query logs, page timers, memory usage, and page arrays.
01:32Let's see an example of that now.
01:34If I go ahead and click on the Display query log and then click on Save configuration,
01:39I see some options have been saved, but where is the information that I'm expecting to be seen?
01:44Let's scroll down at the bottom of the page, and I'll show you exactly where it's that.
01:49We can see that 34 queries have been executed in 15.33 ms.
01:54And obviously, the number of queries in time doesn't have concern, what would be is if
01:59any of these queries were highlighted, that would indicate that there was something wrong
02:03with the database calls being made by Drupal.
02:07If I continue scrolling down, I do not see any highlighted areas. That's a good thing for us.
02:12Let me go ahead and turn this off for now and then click on the Save configuration button
02:17and quickly scroll down to make sure the information is no longer being displayed.
02:21In most cases I use the Devel Module not from this interface, but actually from within templates,
02:27and Drupal functions when theming, the ability to see page, node, region, blocks, and even
02:33view variables that I can use to override or assist me with modifying the Drupal Instance
02:39output, makes the Devel Module something that I always make sure to install and configure
02:45within a Drupal Instance.
02:47In order to get a better idea how we would use this with theming, let's go ahead and
02:52tab over to our favorite Editor and then browse to the Drupal/drupal.fixed/sites folder,
02:59and inside of there we want to open the all/themes/responsive folder, which is the theme that we're currently using.
03:07And in here you are seeing some different files that you may or may not have seen before.
03:12One is this template.php.
03:15This template.php has code that does a lot of overriding or hooks into or pre-processing
03:22or processing of the Drupal API and the output that it is displaying for us.
03:28We have the ability to, as a Drupal themer, manipulate all these variables.
03:34If I go ahead and expand the Includes folder and take a look at, for instance, the process_include
03:40and then look for the specific function called responsive_process_region, I can see a function
03:46here that's been commented out.
03:48This is the KPR function, and this is a function that's built into the Devel Module.
03:53So even though I'm currently not having anything enabled from the admin interface, I do have
03:58ability to still use Devel to output information to the page.
04:02Let's see what happens when I uncomment this, save it, and then tab back over to our browser and go to the homepage.
04:11I'm now seeing some areas with some different content.
04:14Since we're dealing with the regions inside of Drupal, I can see that these are actually
04:18printing out page bottom, toolbar, branding, slider.
04:22If I tab back to over to our Editor, comment this out and save it and then scroll down
04:28a little bit to the responsive_process_page function, and then uncomment the KPR function
04:34here, and then save it and then tab back over to our browser and refresh, I'm now seeing
04:40even more information available to us.
04:43If I actually expand this array, I can see that there is are tons of variables that if
04:48I wasn't using this function, I may not know it existed or that I actually had the ability
04:53to use these or manipulate these when it comes to Responsive Design.
04:58So that we don't display this information on every page, let's tab back to over to our
05:02editor, comment out that function again, save the page, and then refresh it in the browser.
05:08Now we're back to where we were before.
05:10While there are many features that the Devel Module provides us, the ability to output
05:15Drupal variables is the most useful.
05:18Now that we've walked through how to configure and use the Devel Module for our theming
05:23needs, it's time to move on to discussing what responsive and adaptive design is and
05:29the workflow involved in Drupal 7 Responsive Design.
Collapse this transcript
2. Adaptive vs. Responsive Design
What is responsive design?
00:00So what is Responsive Design?
00:02In simple terms, Responsive Design is making sure your design responds to all environments,
00:08from mobile, to tablet, to browser, and even television screens, ensuring your design displays
00:14the most important content, comparable to the amount of viewing area now needs to be
00:19considered on all web design moving forward.
00:22Let's take a look at some websites that take Responsive Design into consideration and discuss
00:27why you would want to design responsibly and the concepts, and techniques that make up Responsive Design.
00:35When you think responsive, you generally think fluid, and a layout that scales from large
00:39to small as the browser resizes.
00:42If we take a look at our drupal.fixed theme, as we begin the resize the browser, we notice
00:49that number one, we get horizontal scrollbars. Number two, we start to lose content.
00:56Number three, our menu disappears, and pretty much the site is starting to look, well, not
01:02very much like a site should look.
01:04If I expand the browser back out, and we take a look at our favorite coffee company, Starbucks,
01:09we're going to start to see what Responsive Design is all about.
01:14Let's take a look some of the features first, the most important, the content.
01:18As we begin to resize our browser, the content begins to scale, items start getting smaller,
01:25yet all the content is still visible.
01:27If I scroll down the page a little bit to where I see even more of the content area
01:32and then begin to resize down even further, we can see some shifting taking place.
01:37Content that was smaller in the right sidebar now becomes bigger and is part of the main content flow.
01:44As I continue to resize our browser down to what we would expect to be the view in an
01:49iPhone or in Android device, we can see that those images and content take even more focus,
01:55and the content becomes more important.
01:57Also, if we take a look at the menu, the menu has completely changed.
02:02These are all responsive characteristics.
02:05As I begin to expand the site out, I can watch the menu change back into what we expect menus to look like.
02:12And if I keep going even wider, I can notice that the menu itself starts to get larger.
02:17And if I hover over items, I have as a dropdown effect that displays even more content.
02:23So taking that in mind how does the page exactly react to smaller screen sizes?
02:29This is one of the major implementations of Responsive Design, known as a Media Queries,
02:34the ability to detect screen sizes, and then manipulate the CSS Hide, Show, or Scale content accordingly.
02:44Another concept you may have seen is moving from a fixed-width pixel-based design to a
02:49percentage based fluid design so that this layout scales according to the browser itself.
02:54Finally, how about the images and how they scale?
02:58This is another common responsive characteristic that we're seeing in the mobile sphere.
03:03We've discussed what Responsive Design is.
03:05We've taken a look at some examples of responsive websites, and why it's so important to consider
03:11this when trying to reach your target audience.
03:14However, before we begin to dive into some different techniques of Responsive Design,
03:19you may have heard another term that describes the same approach we just viewed, Adaptive Design.
03:26Let's take a minute and discuss this term and how it compares to Responsive Design.
Collapse this transcript
Understanding adaptive design
00:00While Responsive Design generally deals with fluid layouts and techniques, Adaptive Design
00:06can be considered a hybrid approach.
00:08That is designing for different fixed-width layouts, one layout browser, one layout for
00:14tablets, and multiple layouts for mobile devices.
00:18Pictures are worth a thousand words, so let's see an example of adaptive layouts in motion with dribbble.com.
00:25This is a great example of Adaptive Design.
00:28The minute you browse to the site and begin to resize the browser, you may think that
00:33this is a fixed-width design at first. What do I mean?
00:37Once I get to a certain section, I notice horizontal scrollbars appear, this screen
00:42is fixed with design to me.
00:44However, if I keep resizing the browser down, once I hit a certain breakpoint, the site
00:50becomes completely fluid. So what exactly is going on here?
00:56Dribbble itself is a fixed-width browser design, but fluid for mobile devices, such as tablets and phones.
01:04Adaptive Designs like this use a lot of the same techniques that Responsive Designs use,
01:09however, unlike strictly fluid designs that start off fluid and remain fluid, Adaptive
01:16Designs generally don't worry about scaling 100%, and instead serve various layouts based off different breakpoints.
01:25The disadvantage, though, of this type of design is that all the data is served to all devices
01:31and may not respond to various screen sizes as we first saw when trying to scale the site down.
01:37This works if you're only worrying about the user experience on specific devices, such
01:41as the browser or tablet.
01:44At this point, though, we've taken a look at Adaptive Design,
01:47the various concepts that make up an adaptive approach and why you may prefer this method over a fluid one.
01:53Generally, though, your client, the budget, and the time constraints will dictate this approach.
02:00But no one approach is better than the other just as long as you're thinking about one
02:04and implementing it with each new site.
02:07Concepts and terms are great, but what type of workflow should we use in reaching our
02:12goal of Responsive Design? Let's discuss that next.
Collapse this transcript
3. The Adaptive Approach
Discovering fixed-width layouts
00:00Before mobile devices started evolving, we were only concerned with the desktop.
00:05However, screen resolutions quickly began getting bigger as monitors became larger and
00:10different standards started to become more formalized.
00:14As a designer, the need to be able to control the layout regardless of the browser or monitor
00:19size, introduced this concept of fixed widths.
00:21Let's take a look at our fixed-width website and discuss some of the pros and cons for
00:28using such design methodologies, along with taking a look at CSS grid frameworks, and
00:33how we can use these to our advantage.
00:36Let's begin by opening the browser and browsing to our drupal.fixed website.
00:41The website we are viewing is a great example of a fixed-width design.
00:44Meaning, until layout was designed using pixel-based measurements, targeted for a specific screen
00:49size to be viewable on most common browsers.
00:52And this is evident the minute you begin to resize the browser, everything just stays
00:58right where it's supposed to be. So what dimension are we staying at?
01:02Well, let's use Chrome to our advantage here.
01:05Command+Option+I opens the developer toolbar, and from here we can inspect the HTML that's being output.
01:12And if we start looking around at the structure of our document, specifically the main region,
01:18and if we expand this and then start taking a look at some of these Divs that are in place,
01:23the container Div, we notice that over in the CSS Style panel, we have a width of 960 pixels.
01:31That number, 960, may sound familiar to you.
01:36You may have heard that before, because it is a common width used by a lot of different
01:41designs seen on the web today.
01:43So much so that CSS grid frameworks have been developed to assist the web developer and
01:48designer with quickly building sites using this standard.
01:53If we browse over to 960.gs, we see the 960 Grid System.
01:58The Grid System provides a user with a 12 column layout that are each 60 pixels wide,
02:04or a 16 column layout that are each 40 pixels wide, with each layout having gutters for spacing between each column.
02:12And if I scroll down a little bit on the page, I can see an example of one site in particular that uses this.
02:19And that is drupal.org itself.
02:21If I click on the Show Grid button, you get a representation of exactly how this grid
02:26is laid out, and how these sites fit perfectly within the 960 pixel width dimension.
02:34So what are the challenges, though, with using a 960 pixel dimension?
02:38So far we've seen that using a CSS Grid Framework to design fixed-width layout can assist us
02:44definitely for making our work look great, and it performs well on desktop.
02:48But how about the mobile sphere?
02:50When Apple introduced the iPhone, there was an explosion in the growth of mobile devices,
02:54and we were faced with the challenge of how to get fixed-width layouts to function on a smaller screen size.
03:00Then Apple went ahead and introduced the iPad, and we had another screen size to deal with.
03:05And then the competition, different form factors, this explosion in the mobile arena created
03:10so many different screen sizes that are fixed-width design just didn't work that great.
03:16So as you can see, fixed-width designs work best in the browser.
03:21They're meant for the browser, they're meant for a fixed dimension.
03:25Knowing where to start or even better yet how to start a fixed-width design can be a
03:29challenge in itself, though, unless you are going to use the 960 Grid Framework for everything.
03:34How does this fixed-width design handle small resolutions and mobile devices that we become accustomed to?
03:40Let's being to answer that question as we take a look at various resolutions and a concept known as Breakpoints.
Collapse this transcript
Understanding breakpoints
00:00You may have heard the term Breakpoints when taking a look at Responsive Design and wondered, what are they talking about?
00:06Well, a Breakpoint is a process in which the display changes based on the resolution of
00:12the device that it's being viewed in, so what does that really mean?
00:16Well, in simpler terms it means that as your viewing area becomes smaller, your content becomes more important.
00:22And a three-column layout may need to become a two-column layout, et cetera, to avoid
00:29unwanted effects like horizontal scrollbars.
00:32To help understand this, let's take a look at some different examples of known device
00:35widths based on browser, tablet, and phones, a great tool for resizing our design.
00:43Here we have our fixed-width design opened up in the browser.
00:46We know from previous discussions that a design is number one, fixed, but also fixed at 960 pixels.
00:54This ensures that looks good at 1024 pixel based resolution, which most common browsers use.
01:01So 1024 pixels, well, that's a Breakpoint in itself.
01:05We've been designing for that regardless of you were even aware that it was a Breakpoint.
01:09But what about non-browser devices?
01:11This is a tricky question, since there are so many different form factors now for mobile
01:16devices, ranging from tablets, to Android devices, to the iPhone and even the new Retina Display.
01:22Trust me, you would either go crazy trying to design multiple versions of your website for
01:27all these resolutions, or you would have your work cut out for you.
01:31Well, one tool that assists us in this is the Responsive Design Bookmarklet.
01:36If you browse over to responsive.victorcoulon.fr, we have a handy tool for Responsive Design testing.
01:46To install it, simply grab the RDW Bookmarklet, and drag it to your Bookmark bar.
01:53Once it's installed, we can use this by simply tabbing back over to our site, and then clicking on this Bookmarklet,
02:01what it does is it provides us with an interface to take a look at the different breakpoints.
02:07Let's begin with iPad landscape.
02:09The iPad landscape is 1024x768 and our site looks great in this.
02:16And the reason being is 960 pixels was built for this particular Breakpoint, but what happens
02:22at the iPad portrait breakpoint?
02:25768 pixels, things don't quite look the way they we are expecting them to be.
02:31But not bad, we could do a little bit of work maybe to get this to look good.
02:36But once we go down to the iPhone landscape, we get it to 480 Breakpoint and then iPhone
02:44in its normal state, were getting down to 320 pixel Breakpoint.
02:48So now if we take a look at the most common Breakpoints for different devices, how does
02:53our fixed-width design look in those various screen sizes?
02:57Well, we know that it doesn't look great in three out of the four, but we need to start
03:02thinking about how we can improve on the design, and make those other Breakpoints at various
03:08sizes more important to us.
03:11Well, there are various tools for testing your design widths, and this RWD Bookmarklet
03:15is great for assisting us with making those decisions.
03:19Once we have made the decision of what Breakpoints we want to design for, how do we go about
03:24applying those different fixed widths?
03:27Well, one such tool is adapt.js, and we will take a look at that next.
Collapse this transcript
Using Adapt.js with Drupal
00:00We started with a fixed-width layout design for the browser but quickly realized that
00:04everyone doesn't use a browser solely for viewing our design and that different Breakpoints
00:09exist that we need to take into consideration.
00:12So, now we decide to make a tablet version of our site and a mobile version of our site,
00:16and I have created three different style sheets based on these breakpoints.
00:20But how do I tell the browser which style sheet to use?
00:22One such way is by using a JavaScript file known as Adapt.js.
00:28Adapt.js will help us to determine the device that we are using and apply a style sheet accordingly.
00:33Let's take a look at Adapt.js, how to use it, and best practices to integrate it with Drupal.
00:39In my browser I have adapt.960.gs open.
00:43The Adapt.js file is just a JavaScript file that will help us determine which CSS files
00:50to load when the browser renders a page.
00:52This is going to allow for us for designing fixed-width layouts based on certain Breakpoints,
00:57and then displaying those layouts accordingly.
01:00As you can see, Adapt.js has some already predetermined Breakpoints, ranging from mobile,
01:05all he way up to large monitors or possibly even browsers being displayed on televisions.
01:11Let's begin resizing the page so that we can see the different breakpoints being reached
01:15and the different design changes taking effect.
01:18As I begin to resize a page, we go from browser to tablet to even mobile, always they are
01:24taking effect based off the different breakpoints being reached, and a substitution of the style
01:29sheet for that particular breakpoint. So how do we utilize this technique with Drupal?
01:35Your first thought might be to search for a module to integrate Adapt.js into your Drupal 7
01:39website, and while I would tend to agree with you that in most cases the module approach
01:44is best, we don't have that option this time.
01:47So, let's take a look at ways to integrate any JavaScript file into your Drupal theming arsenal.
01:53Let's go ahead and start by clicking on the Download button, so we can download the Adapt.js
01:57file to use with our Drupal Instance.
02:00Next, let's go ahead and open up the Downloads folder, and extract the file.
02:05Now that it has been extracted, we need to open up the assets js folder, and I want to
02:10copy the adapt.js script over to my Drupal Instance.
02:15Let's go ahead and choose Desktop/Drupal/ drupal.adaptive and then locate our sites
02:20folder, and I'm looking for the theme, in this case the responsive theme, and inside
02:25of here I have an assets JavaScript folder and I want to place inside of the library.
02:30Once I have this in my library, I need go ahead and call this from Drupal, let's close
02:35this window and then open up over Editor and then locate the drupal.adaptive/sites/all/themes/responsive folder.
02:45Once inside the responsive folder, I want to make reference to that Adapt.js library.
02:49so let's go ahead and click on the responsive.info file, and one thing to note here is that we
02:54want to make sure we call this after any script that's calling this Adapt.js library.
02:59So, I am simply going to copy the last scripts lines, paste it in, and then change the custom.js
03:05to be calling the library adapt.js files.
03:09So, now I have the library in place, I have a reference to inside my .info file, the next
03:15thing I need to do is I need to actually set this up so that the configuration settings
03:21call the correct style sheets when this is fired.
03:23We can do that by looking at the custom.js file next.
03:28Go ahead and save that .info file and then browse back over to assets/js/custom.js.
03:35Another thing to note is we do not want place this inside of the (document) .ready (function().
03:39So, I am just using a variable that needs to be accessible to the script at all times,
03:44we want place this on the outside of our (document) .ready (function().
03:48Go ahead and hit Enter a couple of times to create some space, and then we are going to
03:51go ahead and first make a comment.
03:53This will be our Adapt.js Settings, that way if we come back here, we know exactly what
03:59this particular script is calling.
04:01Then next what you do is create a variable, this variable is for the ADAPT_CONFIG, inside
04:07the ADAPT_CONFIG, there are three different settings that I would like to call.
04:11The first is the Path, the path is going to be where is the CSS folder that contains the
04:16style sheets I want to use, let's enter that now.
04:19That would be the sites/all/themes, the name of the theme, in this case
04:19responsive, the assets folder, and then the CSS folder.
04:30Since I'm entering multiple settings, I need to make sure I have a comma after
04:32here, and then go ahead and enter our second setting.
04:36The second setting is dynamic, meaning that when the page is called, and as the page resizes,
04:42I want this to continuously fire. So, in this case dynamic is true.
04:46We'll add another comma so that we can add our last setting.
04:50This last setting is the range, the range is when one particular pixel Breakpoint is
04:56reached, what style sheet would get called.
04:59Since there were three different Breakpoints that we are interested in, mobile, tablet
05:03and browser, we need to go and enter that range. Let's go ahead and add some square
05:08brackets, since this is going to having multiple ranges inside
05:10of here, and then the first range is going to be from 0px to 760px, and this is going
05:17to call our mobile.css file, I will place a comma, and then put in my second range.
05:24My second range is going to be from 760px, all the way up to 980px and for this I want
05:32the tablet.css style sheet to be called.
05:36Our last and final range is going to be from 980px to 1280px and for this I just want
05:45the standard grid that we already have in place to be called, so this will be for our browsers.
05:50Now that I have the configuration in place, let's go ahead and save this, and then our
05:55third and final step that we need to do is we need to actually create the mobile and tablet style sheets.
06:01So, if we actually open our css folder and right-click on it and say New Text Document,
06:06I want to go ahead and create a mobile.css file, as well as, I want create a tablet.css file.
06:15Inside the mobile.css file I want to create something that is visually different so that
06:18I can actually see this being fired off once we reach that Breakpoint.
06:22The most common element on the pages is the header, so let's look at just changing the background color.
06:26So, let's go ahead and target the header, and we are going to change the background-color:,
06:31and we are going to change this to be #98C4DA, this will give us kind of a bluish tint.
06:40I am going to go ahead and copy this, make sure I save this file and then go over to
06:45my tablet and paste this in and just change the value of my background-color: So, for
06:51our tablet, I want to be kind of a grayish color, so in this case, 757575, save this.
07:00Now with all the steps completed, let's go ahead and browse back over to our Instance
07:04of Drupal, and then one thing to keep in mind is since we made a change the .info file,
07:11we want to make sure that we flush the Drupal cache.
07:13In order to do that we need to be logged in.
07:16Go ahead and log in by going to /user, and then putting in the User credentials of lowercase
07:22admin, same for the Password, and then logging in.
07:25From here let's go ahead and flush the Drupal cache, go back to our Home page and then begin
07:30to resize the browser, there is our great color, so we reached the tablet, as I continue,
07:35we get to our blue color, so we reached on mobile.
07:37So, you can see the adapt.js script is being fired off. Sticking with our fixed-width approach,
07:43we'll now take a look at using adapt.js to apply different styling for our design based
07:48on the Breakpoints we identified.
07:50Having such a tool available to help us and applying the different styling and in turn
07:54making our design more responsive for our end users is a great way to integrate the Adapt.js script into Drupal.
08:02While taking an Adaptive approach to Responsive Design may work for you, it may not work for everyone.
08:07Keeping that in mind, let's move on creating a fluid theme that will allow for a more flexible approach.
Collapse this transcript
4. Fluid Layouts
Discovering fluid layouts
00:00Unlike their pixel-based, fixed-width counterparts, fluid layouts use percentage-based measurements,
00:06and are designed to fit any browser size.
00:08In the case of Responsive Design this allows for the design to render appropriately in mobile, tablet, and browsers.
00:16Instead of having to design various fixed-width designs, fluid layouts allow you to design
00:21a single layout and then worry about how content will flow within your document through various responsive techniques.
00:28Let's take a look at some examples of fluid layouts, some CSS frameworks that use fluid
00:33layouts, and why you would want a fluid design as part of your Responsive toolbox.
00:39Trying to find a good fluid layout only site is actually more difficult than you may think,
00:44since everyone is now doing Responsive Design on top of it.
00:47If we tab over to Google, and we Google the word fluid layouts, we will see that we return
00:52results that date all the way back to 2006 and older.
00:57So, fluid layouts have been around for quite a while, the question is why are we just worrying about it now?
01:03So that we don't confuse ourselves with fluid layouts that more than likely have responsive characteristics.
01:09Let's go ahead and open up the HTML Rendition of our drupal.responsible website that is
01:14part of the exercise files for our premium subscribers.
01:17You can locate the inside of Exercise Files/HTML/ responsive.fluid, let's go ahead and double-click
01:23on the index.html file to open up in the browser so that we are not distracted with the scrolling slider.
01:30I'm going to go ahead and click on the right arrow once to stop it from scrolling.
01:35The first thing you should notice is that the layout seems a little wider than our fixed-width version of our theme.
01:40The reason is that unlike the 960 pixel-based design, this fluid layout starts off at 1140 pixels,
01:46which is more the standard today with larger monitors.
01:50Next, let's grab the right-hand side of our browser and slowly shrink the width of our
01:55viewing area and notice how the content begins to reflow without truly breaking our design.
02:01Unlike our fixed-width design which is based on pixels, and there is a set unit of measurement,
02:06our fluid width design utilizes percentage-based measurements.
02:10So, as the user resizes the browser, the content is able to grow and shrink in response to the viewing area.
02:17Already you should be able to see the advantage of using a fluid design, such as a more user-friendly
02:22design, the amount of extra white space, similar designs that look good on different screens
02:26and most important, the elimination of those horrid, horizontal scrollbars produced by fixed-width designs.
02:34However, though, you might be asking yourself what fluid framework if any I am using?
02:38I have actually Bookmarked a few for us to take a look at.
02:42The first is the 1140pxl CSS Grid, which the responsive.fluid theme that we are looking at is based off of.
02:50Another Grid for you to take a look at would be the twitter Bootstrap, this is another
02:54good CSS framework to use as a starting point when you are thinking about fluid in Responsive Designs.
03:01The last and not necessarily the least is Skeleton.
03:03Skeleton is a Beautiful Boilerplate for Responsive, Mobile Friendly Development and the great
03:09thing about these three frameworks is that there is a Drupal theme equivalent that you
03:13can use as a starting point for any design.
03:16We now review what fluid layouts are, how they differ from fixed-width, and some of the
03:21CSS frameworks that help us in creating a fluid layout.
03:25But how do we actually go about converting our fix-width layout into a fluid width layout?
03:29The answer is all relative, well, so to speak.
03:32Simple math is involved in converting the pixel-based widths to percentage-based widths,
03:37and we will discover that next, as we begin to convert our theme into a fluid layout.
Collapse this transcript
Exploring fluid widths
00:00We know that pixel-based widths are static in measurement,
00:03meaning they do not resize based on our browser size, but we can overcome this by converting
00:08our pixel-based measurements to percentage-based ones.
00:11This all starts with a little math and a top-down approach to tackling our fixed-width theme.
00:16Let's begin, and I am going to take a look at our Responsive Drupal theme in the browser.
00:20Let's quickly look to see what happens when we begin shrinking the browser window.
00:24Once we hit our fixed-width dimension, we have the presentation of horizontal scrollbars.
00:29Knowing this, how do we first go about making our fixed-width fluid?
00:33You may think percentage based dimensions? But exactly how do we ensure our design still looks good?
00:39Well, let's just take a moment and open up our Chrome developer tools, that is Command+Option+I
00:43on the keyboard, or if you right-click anywhere in the HTML and click on Inspect Element,
00:47it will also open up the tools.
00:50One of the things I want to take a look at is what's actually constraining our design?
00:53And if I take a look at the different sections, I am going to see this div.
00:57This <div class= "container, and this repeats throughout most of the design.
01:03Here it is for the section "toolbar", here it is for the <header.
01:05If I scroll down to main, here it is up around the main > section, and if I actually take
01:10a moment and select this or highlight this particular div, I'll see that over in the
01:14CSS panel, I have a width of 960 pixels.
01:19We can change this on the fly by simply selecting the pixel value and changing it by either
01:24moving our arrow up and down or by simply typing a value in place.
01:28Let's see what happens when we change this to be 100%.
01:32Let's go ahead and minimize the upper tools a little bit, and while 100% it definitely turns our
01:37design from fixed to somewhat fluid, we do lose our design flow a bit as well.
01:42Thinking about this for a second, while we want the layout to be fluid, we also want
01:46to set a maximum width that it can confine to so that our design still looks good.
01:52Expanding the Chrome developer tools a little bit, let's go ahead and take a look at this container class again.
01:57Let's add an additional CSS rule to a container by using the Tab key to drop down to line
02:02and enter max width of 960 pixels, go ahead and close the Chrome developer tools, now that
02:10looks a little bit better.
02:11We constrained to 960 pixels when we are on a full browser width, but as we begin to shrink
02:17the browser, it becomes fluid.
02:20So this is step one of converting our fixed-based width, to be more fluid.
02:24We've set the container, which is wrapping all of our elements to be 100% width, with
02:30a max width of 960 pixels.
02:33If I Refresh the page, you can see this snap right back to where it was, and that's because
02:37we've only used the Chrome developer tools to make the changes.
02:40At this point let's now open over favorite Editor and choose the grid.css stylesheet
02:45located inside the asset css folder for our Drupal theme.
02:49Opening up the Editor I want to browse to Drupal/drupal.responsive and then locate
02:55the sites/all/themes/responsive/assets/css folder.
03:01Then if I take a look at the grid.css, this is the CSS that makes up our framework for a layout.
03:08Let's go ahead and make the changes that we did on the Chrome developer tools permanent,
03:12by actually modifying the container class.
03:15We are going to go ahead and change 960 pixels to be 100%, and we are going to add that max
03:20width rule and set it to 960 pixels.
03:23I am going to go ahead and hit Save to save my changes, then I am going to go ahead and
03:27tab back over to the browser, hit Refresh, and go ahead and resize real quick just to make
03:32sure that it took effect, and it did.
03:34One thing you may notice, though, is when I get to a certain width, I have a column begin to drop out.
03:41Responsive layout section, which was right next to HTML5 in CSS 3 is not quite fluid,
03:48and we need to take a look at how we can change that.
03:51Go ahead and open up the Chrome developer tools again, let's go ahead and inspect this
03:55particular section that's inside the <div main, inside the container=class, and inside this features section.
04:02From here I can see three different asides that have a class of four columns, and in
04:08this we have a width of 300 pixels.
04:10So, how do we go about converting 300 pixels to be percentage based?
04:17Well, it's simple, it's math, and that math is Target divided by Context equals Results, or the percentage
04:25that we are looking at. Well, what's our context?
04:28In this case it's our container, so 300 divided by the 960, that will give us the result that we are looking
04:35for, and that's what we are going to need to change that pixel, too, in a percentage based measuring.
04:41Let's do that now.
04:42We are going to take a look at the fourcol class, so it's currently 300 pixels and do the math now.
04:49We have 300 pixels divided by 960 pixels gives us 0.3125, but since we are looking at a percentage base,
04:59we need to round that up.
05:01So let's multiply that by 100, and that gives us a 31.25%.
05:07Let's go ahead and make that change to our rule.
05:09What I generally like to do is actually make a CSS comment that has the Target divided by the Context equaling the Result
05:17inside the common as well so that I have a baseline of what my context is as I go back
05:22and look through the CSS style sheets later on. So 300/968=31.25%.
05:34Now let's go ahead and change the 300 pixels to that percentage that we just calculated, 31.25%.
05:43Let's save this, tab back over to our browser, and let's hit Refresh.
05:47Now let see what happens when I begin to resize the browser, looks a lot better, the column
05:53doesn't drop out until it reaches certain Breakpoint, and that's actually being dropped
05:57out due to another asset on the page. So, the fluid widths are actually taking affect.
06:02I want to take a look at one more example here, and that is if we scroll down to the bottom
06:07and take a look at the footer, I now have four columns here at the bottom that are still not a fixed-width dimension.
06:12I want to go a head and take a look at these in the Chrome developer tools by opening up
06:16the Footer and then the Container, and there is a row here that has these particular A
06:21sites, and if I select this I see that the width on here is 220 pixels.
06:26Well, knowing that our math here is Target divided by Context equals Result, let's go ahead
06:31and calculate what the percentage for this should be.
06:34Find the threecol class, I am going to copy this comment real quick.
06:38We will go ahead and change the value, so in this case 300 will be 220.
06:42Our context is still same, it's still 960 pixels, however, our math is going to change a little bit.
06:47So, let's go ahead and open up the calculator, go ahead and clear it out and say to 220/968 equals--
06:54remember, we got to turn this into a percentage-- we are going to multiply this times 100, and
07:00this is going to give us 22.9166666667%.
07:06At first you maybe thinking, I am just going to round that number up, and I am going to
07:11say, stop, leave that number exactly how it is.
07:14Most browsers today can do that type of math, and the more accurate that calculation is
07:19the better fluid design we are going to have when we go to look at this in the browser.
07:22So, knowing that we have that number, I am just going to go ahead and actually select
07:26the calculate itself, and Command+C, or Ctrl+C on a Windows machine, and copy that value
07:32and then actually go ahead and paste it in.
07:35Do the same over here for the pixels, add a percentage sign to the end, go ahead and
07:39save my changes, tab back over to my browser, and Refresh.
07:44Now at the Footer section, highlight it on a browser, let's go ahead and resize and see
07:48what takes place, again, you saw the one column dropout, and that's because it has to do with
07:53images, which we are going to tackle a little bit later, but the column themselves are shrinking
07:57the way they were expecting them to shrink.
07:59At this time I am going to let you go ahead and modify the remaining classes inside of
08:04the grid.cssstylesheet to convert the pixel-based measurements to percentage based ones.
08:11Now that we have converted all of our pixel-based to percentage based measurements, we are one
08:16step closer to making sure that our fixed-width design is more fluid.
08:20Now that we have a good understanding of how to convert pixel-based measurements to percentage-based
08:25measurements, let's move on to tackling the margin and padding our containers so that
08:29they flow better within our HTML document, as we resize the browser.
Collapse this transcript
Working with fluid margins and padding
00:00Now that we know the math, we should probably continue cleaning up our design by addressing
00:04the margins and padding of our containers.
00:06Without addressing this, we would have content that doesn't flow nicely as our browser resizes.
00:12Before we start, though, it's not as easy as it sounds, unless you know that margins and
00:16padding are handled a little bit differently. It's all about context.
00:20Let's explore what these differences are as we look at making margins and paddings fluid.
00:25Utilizing our Target divided by Context equals Results rule, we'll want to modify the margins and paddings
00:30on a layout by keeping in mind that the context can change based on the relative parent element.
00:36Let's continue by tabbing back over to our Editor, and I have the grid.css open from the previous video.
00:42If we scroll down on the bottom, we'll find our first instance of margin.
00:46In this case, margin-right, which is actually assigned to every single class that deals
00:51with columns and currently it's set at margin-right of 20 pixels.
00:57So how do we do the math on this? Simple. The same way that we've been doing it.
01:01Since these columns are actually contained within the container, the context has not changed.
01:07So our math would actually be 20 pixels divided by 960 pixels to give us our percentage-based
01:13measurement that we're looking for.
01:16Like usual, I'm going to go ahead and create a comment first, and actually put in my figures
01:19that I'm going to be dividing against so that I actually can reference these numbers again later.
01:24So 20px/960px =, and close the comment and then I'm going to go ahead and open up the
01:30Calculator, doing the math 20 divided by 960 equals, and then multiplying this by 100,
01:37since we're dealing with percentages, gives us 2.083333333333, to infinity.
01:44Based off this calculator, let's go ahead and just copy this and paste the figure in.
01:49Make sure to put the percentage mark on the end of it, and then let's change the 20 pixels to that number.
01:55Now that I have that, let's go ahead and save it, tab back over to our browser, and Refresh.
02:00I'll go ahead and scroll down to the bottom now, previously we had this wrapping taking
02:06place with our gallery section.
02:08So if I resize the browser now, you can notice that that column no longer drops off the page,
02:13and that's due to the margin right now being a fluid measurement percentages.
02:18The same held true for our responsive layout column up in our features section.
02:23We can now see that this is becoming more responsive and more fluid, because not only
02:27does our container and our columns contain percentages, but now our margin for those columns does as well.
02:34Let's continue this conversion with tabbing back over to our Editor, and this time let's
02:39take a look at the layout.css.
02:42Let's focus on the primary layout areas first. Toolbar, Header, Main, Footer, and Copyright.
02:48Since all these regions share the same context of 960 pixels, doing the math that we did
02:52previously should be pretty simple.
02:54A simple rule of thumb, however, when I develop a Responsive Design is to only worry about
02:58the widths and the left and right margins or paddings.
03:02There's no reason to actually go ahead and convert the tops and bottoms, because we're not dealing
03:07with a browser that stretches from top to bottom, but from left to right.
03:11Let's go ahead and scroll down layout. css page until we find the footer section.
03:16To better help visualize the changes that are going to take place, I'm going to do
03:19some real quick clean-up.
03:21I'm going to go ahead and move this down from a single line to multiple lines so that we
03:25can actually add our comments like we did before when we get ready to tackle the padding
03:30here on the footer element.
03:31And now that we take a look at the padding here, the first figure that we need to actually
03:35calculate for is the 10 pixels, the 43 pixels is for the top and the 40 pixels is for the bottom.
03:42Knowing that, let's go ahead and take a look at our conversion.
03:45Adding our comment in again as usual, we have 10 pixels divided by, in this case our context
03:51is still 960 pixels, equals, and let's go pull up the calculator again.
03:56I have 10 divided by 960 equals, multiply that times 100, and that gives us our figure that we're looking for.
04:04Now copy that, paste it in, add the percentage, and then go over to my 10-pixel increment
04:11and change that as well. Go ahead and save my changes.
04:14One of the areas I want to take a look at really quick is the Copyright.
04:16We're going to modify the padding on this as well.
04:19Let's go ahead and do a little bit of house cleaning, and since we're dealing with--you guessed
04:23it--10 pixels again, we should have the same calculation as before.
04:26Add the comment first, 10 pixels divided by 960 pixels equals, our 1.04166667%, close
04:38our comment and make sure we replaced the 10 pixels with that percentage.
04:43Again, save the page.
04:45So now our footer and copyright for our padding has been taken care of.
04:49Let's go ahead and refresh the page in the browser to take a look at what happened.
04:52So we're dealing with the footer and with the copyright section, and so the padding
04:56now has become fluid as well.
04:59So far we learned to deal with the context of 960, but earlier I'd stated that the context
05:04changes depending on the relative parent element.
05:07This happens once you begin nesting elements inside one another.
05:11For example, let's take a look at the gallery section of our footer.
05:14We have a list with four images, all containing margin and padding.
05:18The first parent element has a width of the three-column class.
05:21So our new context in this case will be the value that that three column class had.
05:27Let's go ahead and tab back over to our Editor, locate the image list, here it is here, do
05:32some real quick house cleaning.
05:34Here we have multiple elements that we need to convert.
05:36We have a width, we have a margin right, we have a margin bottom, and we have padding.
05:42So based off of the conversion here we need to look at what the context was, and like
05:46I had said previously, our context for this instance is no longer 960 pixels.
05:52This is based off of our grid stylesheet for the three columns, which in this case--and
05:57this is a reason why I do comment is because we need to know what that figure was.
06:02Trying to figure out what 22.91666, et cetera, was in pixels would be nearly impossible,
06:09but knowing that the three column class actually had a container size of 220 pixels, that gives
06:15us our new context to divide for.
06:18So if we go back to the image list, back on the layout.stylesheet, we can then do the
06:22math, add a comment in again.
06:25Here we have 80 pixels divided by 220 pixels, because that's the parent elements container is equal to.
06:33Let's go ahead and open up the calculator, clear out the previous value, and do 80 divided
06:38by 220 equals, multiply that times by 100, and we get 36.3636 et cetera, percentage.
06:46Let's simply copy that, paste it in place, add the percentage, and then make sure we
06:52replace the width with that percentage base.
06:55At this point I'm going to let you make the remaining changes to any margin and padding
06:59inside this specific stylesheet. Keep in mind, though, that the context may change.
07:05So make sure you take a look at what the parent element is in order to determine that context.
07:10Now that we have finished our conversions, this is the main reason your parents told
07:15me that you would use math when you grew up.
07:17Understand the subtleties of how context comes into play when converting pixel-based margins
07:22and paddings is important to making sure content flows properly.
07:26Knowing how to locate that context is even more important when you're dealing with nested parent elements.
07:32Speaking of content, how about text itself?
07:35How do I make sure that it's responsive or fluid in my design?
07:39Let's explore that next.
Collapse this transcript
Making text fluid
00:00When you start to look at making text fluid and flexible, you need to begin with an understanding
00:04of baselines for your CSS and the differentiation between pixels and em based units of measurement.
00:11Let's begin by taking a look at what a baseline is and how it sets the basis for how our font
00:16size will render in the browser.
00:18Everything we've been doing so far is dealt only with widths, margins, and padding.
00:22However, our text has remained the same size.
00:25As we have found out by now, this is due to the pixel-based nature of measurements.
00:30Instead, though, it makes more sense to convert those pixels to be em based. And you may be
00:34asking yourself what is an em?
00:36Well, an em is a relative unit of measurement based on the letter M.
00:40The size of em is determined in relation to the size of its context.
00:44So we need to make sure we set a baseline for us to even have a starting context to begin with.
00:49Go ahead and tab back to your Editor and open up the base.css stylesheet and take a look at
00:53the CSS rule for the body element.
00:56Not the first one, but the one that actually deals with typography.
01:00In this case we're looking at a font of 16 pixels with a line height of 26 pixels.
01:06Both of these measurements we will look at converting to be em based.
01:10However, we need to have a baseline to start with, and in most browsers 16 pixels is the equivalent
01:16of 100% when dealing with font size.
01:19This rule sets our baseline font size, and once we begin converting our pixels to ems
01:23it will allow for us if needed to increase or decrease the font size throughout our entire
01:29document by simply changing that percentage.
01:32Let's take a look at actually how that works before we start our conversions.
01:36I'm going to add a new rule here for the body.
01:38And I'm simply going to say font size is 100%, so 16 pixels is 100%.
01:46If I save this real quick, and I tab back to our browser, and I Refresh, you're not
01:51going to see anything happen, okay.
01:53The font remains the same, and that's because the browser is already defaulting to that 100%.
01:58Let's go ahead and change this real quick and see what we get.
02:00I'm going to go ahead and change 100% to be 60%.
02:04Save this, tab back over, and then let's Refresh.
02:07We notice some changes, more specifically with the body text or text that's inside paragraphs.
02:13And the reason being is because there is not a pixel-based measurement set on those.
02:17So, when we start our conversions, and we actually start modifying our headings for
02:22both of the font size, as well as a line height, when that percentage changes, those will respond to that.
02:29So they will be more fluid and flexible when we start resizing our browser down to tablet and to mobile.
02:36Tab back over to our Editor, let's go ahead and change that percentage back to 100% because
02:40we're really not going to deal with currently.
02:42What I do want to take a look at, though, is our headings.
02:45And let's do some real quick housecleaning just to make it easier for us to do commenting.
02:48First thing I want to do is talk about converting font sizes.
02:52Let's begin by converting our h1. In this case our context is 16 pixels.
02:57Remember, our body sets the context.
03:00So let's go ahead and add the comment, and we're going to do 46 pixels divided by 16
03:07pixels to give us our, not percentage, but em-based value.
03:12Let's go ahead and open up the calculator and do the math, 46 divided by 16 equals 2.875 ems.
03:22Remember, there's no conversion to percentages here.
03:25So we're not multiplying this number by 100. So the actual value that we want is truly 2.875.
03:31I'll copy this, I'll paste it in, and then add em, since we're doing an em based conversion,
03:37close my commenting, and then change my 46 pixels to be 2.875 ems.
03:42I'm going to go ahead and save the work, tab back over to the browser and then Refresh.
03:49Really do not see a change, and that's because the pixel-based measurement and em based measurement currently match.
03:55Tab back over to the Editor and do the same thing for the font size of the h2.
04:00Again, some real quick housecleaning, and let's do the math.
04:04We have 28 pixels divided by 16 pixels, open up the calculator, clear out the previous
04:10value, 28 divided by 16, that gives us 1.75 ems, go ahead and close our comment.
04:18Go ahead and actually physically change the font-size over here.
04:21Make sure it's em based and save. So that's conversion of the font sizes.
04:27What about the line height?
04:28One thing to note is when we convert our line height that our context is no longer the base
04:33of the body element, but it's the base of the actual element that we're dealing with, in this case the h2.
04:41So the conversion would be, in the case of our h1, it would be 50 pixels divided by 46 pixels.
04:47And this is something that's often missed when doing conversions.
04:52In most cases or for reason your text looks off, it's more than likely that you've used the wrong context.
04:58Let's go ahead and do the conversion now, 50 pixels divided by 46 pixels is equal to 50 divided
05:06by 46 equals--and we have this really large number here, but again, we want to keep these
05:12exactly the way the calculator spits it out to us.
05:14So go ahead and copy this, paste it, add the em to the end, close the comment, and let's
05:19change it for the line height over here, paste it in, make sure that em is there, save.
05:24Let's go ahead and tab back over the browser and then Refresh.
05:27Again, we're not seeing a change, and this is exactly what we want.
05:30If you saw huge fluctuation, again is because you've used the wrong context for your math.
05:36I'm going to tab back over to the Editor and at this point I want you to go ahead and go
05:40through the remaining font sizes inside of our base, grid or layout.stylesheets and do the conversions.
05:48With the conversion done and our work saved, let's tab back over to the browser.
05:51Let's go ahead and Refresh, and let's see what happens if we start resizing.
05:56We haven't seen much change, and that's because the base font-size hasn't changed.
06:00Little bit later when we start talking about Media Queries, we'll actually take a look
06:04at modifying that base font size.
06:06In fact, let's see a real quick sample of that now.
06:09Tab back over to your Editor, currently our font-size was set at 100%, and when we had
06:14changed this, we only saw the paragraph and the body copy changing.
06:18But now that we have converted our headings both the font size and the line heights, let's
06:23go ahead and modify this number back down to 60%, save our work, tab back over to the browser and Refresh.
06:30Now we can see that both the headings, the line height, and all the text has become fluid.
06:36Everything is responding to the environment based off that base font-size changing.
06:40Make sure to tab back over to your Editor and change that back to 100%.
06:44We want to make sure the font size stays at 100% for right now, because we do not want
06:49any confusion later when we start viewing this with Media Queries.
06:53Responsive typography by itself could be a profession, but having a basic understanding
06:57of baselines and pixel to em conversions, should give you a good foundation to build upon.
07:03By now our design is starting to flow much better as our browser window is resized.
07:08But so far we've only been dealing with textual elements and their containers.
07:11What about images or videos, which generally have a fixed width and height?
07:16Let's take a look at that now and how we can make images in media more flexible with Drupal 7, Responsive Design.
Collapse this transcript
5. Fluid Images and Media
Discovering fluid images
00:00Of course, most designs have images as part of their layout, whether in the form of a
00:04featured image in a blog post or another piece of content, and again, in backgrounds in your
00:09CSS for various visual interfaces.
00:12So how does an image flow in the content of your design? With layout containers using percentages
00:17and text using ems, how does the pixel-based image look?
00:22Let's take a look at images in our design and see exactly for ourselves what happens.
00:26Let's start by opening up the drupal.responsive website in our browser and navigate to our blog page.
00:31Next, let's adjust the browser width we can see that most of our page responsive with
00:36the exception of our blog post images.
00:39What we're seeing is that the image is breaking out of the parent image and is not constrained
00:43within its container when resized.
00:46So how do we force an image to be constrained within its parent element so that it becomes fluid? Simple.
00:51Set the max-width of the property of the image to 100%, let's try that now by tabbing back
00:57to our Drupal Instance in the Editor and open up the base.css document.
01:02With our Editor open, navigate to Drupal/drupal.responsive/ sites/all/themes/responsive/assets/
01:11CSS and then base.css, let's locate the CSS common for images and add the following CSS rule.
01:19Once we want to target the image element, we'll create a rule like such, and from here
01:24we actually want to add a max-width of 100%, save your changes and then tab back to the
01:30browser and Refresh the page.
01:33Now when we resize the page, we'll notice that the actual image for our blog post scales.
01:38Now it doesn't scale perfectly, but it does shrink in the width.
01:42Our blog post image is now constrained to the parent element and resizes.
01:47What a change one simple rule does?
01:49The other nice thing about the CSS rule is that it also applies to most fixed-width elements like HTML5 video.
01:56To do this let's modify our CSS rule to include other elements, such as embed, object, video,
02:00go ahead and tab back over to the Editor and on our image element let's add a comma and
02:06actually add embed, object, and video.
02:10So now the max-width of 100% will be targeted against image, embeds, objects, and video elements.
02:17One thing to note about this technique, though, is the lack of browser support in IE 6 and below.
02:23Now that we understand how to make images fluid, we are all set for mobile viewing. Or are we?
02:27While we are telling our images to scale, we are still serving at the same size image to mobile devices.
02:33In most cases that may not be an issue, but if your bandwidth impaired, imagine the user
02:37experience trying to set up a large image that has just been scaled down.
02:41We'll discuss some ways to handle these challenges a little later.
02:45For now we've viewed how images can become fluid, the pros of ensuring our image is responsive
02:49in relation to mobile audiences and fluid image techniques.
02:53Now that we have seen just how simple it is to make images fluid ourselves, let's move
02:57on to making changes to our Drupal design to ensure our images don't break the flow
03:01of our content, as we make it more responsive.
Collapse this transcript
Exploring fluid image techniques
00:00While working with images in static HTML is simple, there is always a challenge with Drupal
00:05and the HTML it outputs.
00:07We know how to make images be fluid within our design.
00:10However, Drupal automatically adds both width and height to any images that it displays,
00:16this will break our fluid technique.
00:18So let's dive into Drupal and see how we can modify how image attributes are displayed
00:22to ensure our max-width properly displays in all browsers.
00:27Let's begin with viewing the responsive.drupal website in our browser.
00:30If we browse to the blog post page and then began resizing the browser, we can see that
00:35while our image is scale in width, they don't scale in height.
00:39So how do we go about fixing that?
00:41At first thought you may think, well, can I just override the CSS? Well, let's see.
00:46Go ahead and open up the Editor locate the image element CSS rule, and let's add another
00:52CSS class here called height: auto.
00:56In other words, we're telling the height to automatically adjust for any images, embedded,
01:01or objects, and videos, save the work, Tab back over to the browser Refresh, and now
01:06let's try resizing again. Perfect. Or is it?
01:11One thing that we do know about Drupal is width and height attributes are automatically added.
01:17So even though they seem to work perfectly, it only works in major browsers and IE 9. So now what?
01:24Well, Drupal allows us through their API to override various functions through altar,
01:29preprocess, process, and theme functions.
01:32Knowing this we can take advantage of the function that outputs images and their image attributes.
01:37You'll need to know how to do a little PHP, but even with a limited knowledge you can
01:41achieve the results that you want.
01:43First, let's inspect our images inside of Chrome by right-clicking on the element and choosing Inspect Element.
01:50This will open up the Chrome developer tools and highlight the image element for this particular image.
01:56We can quickly see that there is a width, and there is a height, and we need to make
02:00sure that we modify this image element to remove those attributes, to ensure that both
02:05are max-width and height attributes work properly in all browsers.
02:10So how do we go about doing that?
02:12Go ahead and tab back to over to our Editor, and inside our editor there is a file called template.php.
02:19The template PHP files where you can place any functions that override the Drupal API.
02:24As we can see, I already have references to a multitude of different overrides which are
02:27just best practices for our theme already, but you can ignore those for now and feel
02:32free to look at them later.
02:33What I want to do is focus on creating our first override, so go ahead and scroll down
02:37to the bottom of the page, and let's add a quick comment, so two forward slashes, and
02:43this function is actually going to remove the height and the width from Drupal images.
02:48Next, we want to create a function.
02:50The name of this function is going to be the name of our theme, in this case responsive_
02:56and then the name of the preprocess function that we want to override, in this case, responsive_preprocess_image.
03:03Now this function actually takes an attribute, and this attribute is actually the variables attribute.
03:08The variables attribute represents the variables array that holds multiple values that are
03:13output by Drupal. Let's go ahead and add that attribute now.
03:16We're going to pass it by reference, let's say &$variable, let's go ahead and open and
03:22close our function, and then we're going to tab through, and we're going to do a simple
03:26foreach loop, so foreach, open and close foreach loop, and what we want to iterate through
03:32is the width and height setup as an array so that we can unset these.
03:39In other words remove these as this image is being preprocessed.
03:44Inside of our array it's going to width and height, and we want to do this as a key, and
03:49then inside the foreach loop we want to unset the variables key value, with the key value
03:55holding the array of width and height.
03:57So what we're saying here is as you go and iterate through the loop, please remove the
04:01width and height from any image that you are about to output.
04:05Let's go ahead and save our work, and the first thing I want to do is make sure that any time
04:09we add anything to the template.php file or any code in general that's overriding Drupal,
04:14we need to make sure that we flush the cache.
04:16So let's go ahead with our work saved, tab back over to the browser, go ahead and close
04:20the Chrome developer tools, and we need to make sure we log in.
04:24So let's go ahead and replace the word blog with /user and then from here go ahead and
04:28log in with your credentials, lower case admin, both for the username and password, let's
04:33go ahead and flush the cache, go back to our blog page, and then I want to scroll down,
04:39right-click and inspect the element, and we can see now that the width and height has been removed.
04:45Modifying Drupal output through the use of preprocess functions may seem a little challenging
04:49at first, but you truly do not need to be a PHP guru to accomplish it.
04:54We have seen how we can change the HTML output of Drupal to remove width and height to images
04:58and modify our CSS properties to make image to display at max-width.
05:03How about video, though? Let's explore that next.
Collapse this transcript
Working with fluid media techniques
00:00Making images flexible or fluid was simple, but how about videos?
00:05That depends on what your definition of video is and how you display video in your design.
00:10If you'll be using the HTML5 video on it then the answer is yes, but nothing is quite that simple is it?
00:16Best practices would suggest that you do not serve video from your web server.
00:21Most users are using a service such as Vimeo or YouTube.
00:25let's take a look at using one of these services, any issues you may face, how to work around
00:30them to ensure your video is fluid, and how to implement these techniques in Drupal.
00:35Previously, we saw that by adding a simple max width of 100% and height auto rules to
00:40the image element assisted us with making images responsive.
00:43You may not have noticed, though, that these same rules were also applied to the video,
00:48object, and embed elements.
00:49While this trick works for HTML5 video, it doesn't yet work for non-HTML5 video elements.
00:56So, how we go about ensuring that video services such as YouTube and their use of frames or
01:01embedded code work responsibly as well?
01:04Let's go ahead and take a look at how we can do that by browsing back to our Drupal instance
01:09to our Blog page and then for the specific blog itself.
01:13So let's go ahead and click on Responsive Design.
01:15If you're not logged in, make sure and log in, because what we are going to do is actually edit this page.
01:20I want to go ahead and click on the Edit tab.
01:22I then want to scroll down to the Body section, and this where we are actually going to put in some embed code.
01:27In a New tab, I actually have open YouTube, and you can use any YouTube video that you
01:32want, but I have one here from lynda.com and what I want to do is I want to share this on the blog post.
01:38So if I actually scroll down a little bit and click on the Share button, this opens
01:43up an option for me to use a link, in this case of an email, or what I am actually looking
01:48for is the Embed code.
01:51We'll notice real quickly here that embedding YouTube link actually uses iframes, and iframes
01:57do not work with the max, width, and height auto rules.
02:01We need a way to work around this.
02:03Go ahead and copy this, tab back over to our Drupal instances, and let's actually click
02:09on the Source button for a WYSIWYG, and then paste this in.
02:12Now once again by itself this won't work.
02:15So what I want to so is actually wrap a div tag around this and give it a class and in
02:21this particular class we will call it video container, make sure I close it, with a closing > </div >.
02:28Then I want to save this.
02:30At first you may not see the actual video show up.
02:33In the reason being is we need to refresh the page in order for that to take effect.
02:37Now that we have refreshed the page we can actually see the Embedded YouTube video.
02:40If we begin to resize the browser, we can actually see that our flow for a media here actually is broken.
02:47You can see that we are back to fixed-width issue with our embedded video not scaling at all.
02:51However, when we added the embedded video, we wrapped it in a <div container with a class="video-container > ".
02:56We are going to use this to apply two different CSS declarations to force our embedded video to be fluid.
03:03Go ahead and open up the Editor.
03:04I want go ahead and navigate to Drupal/drupal.responsive/ sites/all/themes/responsive/assets/css/layout.css stylesheet.
03:17I want to go ahead and scroll on down to where I find the elements that are for our blog post.
03:22So here I have post-title, post-image, and right after the button for readmore is where
03:27I am going to actually add my CSS rules for the video-container and how any iframes, objects,
03:34or embedded elements flow inside of that container.
03:38Let's go ahead and create a comment.
03:39In this case I am going to call it Video and then I want to go ahead and create a class for a video container.
03:44So .video-container open and close my class, and inside here I want to make sure the position is relative, a padding
03:54on the bottom of 56.25%, a padding on the top of 30 pixels, a height of 0, because remember
04:05we want the elements inside to fill the container.
04:07So we don't want to specify a height.
04:09Then we want to make sure the overflow is hidden.
04:13So this takes care of our video container.
04:15How about for our video container that contains an iframe, or a video container that contains
04:22an object, or one more a video container that contains in the embedded elements?
04:28In case I want the position to be absolute.
04:32I want a top 0, a left 0, a width of 100%, and a height of 100%.
04:41With my two CSS declarations completed let's go ahead and save our work, tab back to our
04:46browser, Refresh the page, and then let's go ahead and resize the browser.
04:52Now our media is fluid just like our images.
04:55While I always prefer a CSS approach to any challenge, the CSS technique that you use
05:00may not always be compatible with all browsers.
05:03This introduces us to a jQuery script that we can use called FITVIDS, and this can be located fitvidsjs.com.
05:11If we scroll down at the bottom of the page we can see this as a lightweight easy to use
05:14jQuery plug-in for fluid with video embeds. Let's go ahead and click on the Download button.
05:20This will open up the code over in GitHub, and then go ahead and download this as a zip
05:25file, and then browse to our Downloads folder.
05:29Extract the file, go ahead and open up the folder, and then I want to copy the jquery.fitvid.js
05:37file over to my JavaScript library for my Responsive Drupal theme.
05:42Go ahead and copy that now and then go to the Desktop/Drupal/drupal.responsive/sites/
05:48all/themes/responsive/ assets/js/library file.
05:55Paste that in place.
05:56Now that we have the library in place let's tab back to our Editor, locate the JavaScript
06:01folder, and then our custom.js script.
06:04Now that we have the fitvids library we need to make a call to it from our custom.js file.
06:12Let's go ahead and make a JavaScript comment, call this FitVids and then what we want to
06:17do is we want to able through jQuery to target any class that we give fluid-video.
06:25The action that we want to perform is this FitVids action that will call the FitVids
06:29library to make any of these images fluid. We can do that by applying the FitVids function.
06:36Now let's add a reference to the FitVids JavaScript to our themes.info file.
06:40Go ahead and locate responsive.info.
06:43Then we are going to go ahead and copy this scripts
06:45metadata, and right above our custom.js
06:48call we are going to actually change this to target the FitVids script.
06:52If I open the library file I can see this is called jQuery.fitvids.js and just look
06:58here inside of a library folder.
06:59So I need to make sure I put lib/ and then the name of the file jQuery.fitvids.js.
07:04Go ahead and save that, tab back over to the browser, go ahead and click on Edit, locate
07:13the body element again, click on Source, and then from here we want to go ahead and change this
07:18class to match the class that we are trying to target.
07:21In this case, fluid-video.
07:25Save the page, and remember I said with embedded object or iframes you may need to refresh twice.
07:32There we go. One more thing.
07:34I can automatically see that we forgot to do one stop.
07:36This is common step that's forgotten when we actually are writing any code, and that is flushing the cache.
07:42Let's scroll back up or click, flush the cache, scroll back down, and now I can see that's
07:47actually the same width.
07:48If I begin to resize the browser, I now see that this has the same effect.
07:53The nice thing about using this effect, though, is this will actually work on all browsers that support JavaScript.
08:00We have seen the easy and not so easy way to work with video in Responsive Design and
08:04the challenges that come with using different services such as Vimeo and YouTube with embeds and iframes.
08:10Facing the challenge head on we introduced FitVids jQuery script to compensate for nonstandard
08:15use of video, and now have our video just as fluid as our images.
08:19Next, we'll taking to look at Media Queries and how we can utilize those with Responsive Design.
Collapse this transcript
6. Media Queries
Introduction to media queries
00:00We're all familiar with writing CSS for screen and print, but what about different browsers or device sizes?
00:06CSS 3 introduced a new technique known as Media Queries which allows for us to check
00:11for various conditions and apply different stylesheets or different CSS rules depending
00:16on the physical characteristics of devices and browsers.
00:20While there are quite a few features that you can detect for, in most cases you will
00:25be dealing with the min and max widths to help determine what device is viewing our design.
00:30Let's take a deeper look into how Media Queries work and an example of Media Queries in action.
00:36To best describe how Media Queries work let's take visual tour of an example brought to us by A List Apart.
00:43Taking a quick look at the site you may notice of the browser window is a little bit wider
00:47than the screen we're recording on, and that's because of the media query that we are currently
00:52looking at has a minimum length of 1300 pixels.
00:56As I grab hold of the browser and window and begin to scale it down we'll automatically
01:01notice that the navigation drops from the top navigation to a side navigation, and we
01:06go from 6 columns to 3 columns.
01:10As I continue to resize our browser down more we'll hit another breakpoint where the navigation
01:16pops to the top, and we go to a one column for the content and the three columns for the images.
01:22So exactly how is this being pulled off?
01:25Let's go ahead and open up the Chrome developer tools and take a look at the stylesheet that
01:31is driving in this design.
01:32If I go ahead and expand the style element, and I scroll down we're going to see the introduction
01:38of a new CSS attribute.
01:41This is known as the @media attribute, and it's the beginning of Media Query.
01:46It allows you to add expressions to the media type to check for certain conditions based
01:50on width, height, color, and more.
01:53By using Media Queries presentations can be tailored to a specific range of output devices
01:59without changing the content itself.
02:01In the case of A List Apart they are checking for any device that has a max width of
02:06400 pixels or a max width the 600 pixels, and in the case of the min width of 1300 pixels,
02:12which covered large screens.
02:14You can use Media Queries to enhance your design if you're working from a mobile first
02:18approach, or you can use Media Queries to filter style, and when working from a browser down.
02:23You maybe thinking that the theme is identical to the adaptive approach when using adapt.JS
02:28to display stylesheets based on breakpoints.
02:31While it is similar we are not using any JavaScript and instead we're using a pure CSS approach to design.
02:38While we've taken a look at what Media Queries are, how Media Queries allow us to check for
02:42various conditions within the browser or device.
02:45And an example of Media Queries in action it's not enough just looking at concepts and examples.
02:50Next we're going to dive into creating our first media query as well as take a look at
02:54the new Viewport meta tag and how to test your Media Queries as we continue a with Drupal 7's Responsive Design.
Collapse this transcript
Writing our first media query
00:00Now that we have a better understanding what media queries are, it's time to dive into
00:04writing our first media query.
00:06We'll begin by taking a look at the proper syntax for creating media queries, including
00:11the various ways to write media queries and the basic breakpoints for different devices.
00:16We'll also look at some tools for testing our media queries, discover some of the pitfalls
00:20of devices and how to overcome them with the use of the viewport meta tag on a way to creating
00:26a more responsive Drupal theme.
00:28Let's begin by opening up our editor and browsing to our Responsive Drupal theme folder.
00:33Drupal/drupal.responsive/sites/all/themes/responsive that will take us to the theme
00:40folder we need, and from here what we want to do is go ahead and open up the layout.css
00:46file and scroll down to the bottom of the page so that's located in assets/css, and then layout.
00:53By scrolling down to the bottom of the page we're actually going to be entering our first
00:57breakpoints and our media query to be able to test for those different breakpoints as
01:02we review these in the browser.
01:04The first breakpoint that I want to test for is the Tablet.
01:08I'm going to go ahead and start off by creating a CSS comment.
01:10This will provide the placeholder so that we can go back and find this media query later.
01:15The first thing I need to do is actually create the media query attribute or the media query
01:19syntax that we'll be using the test for the Tablet breakpoint.
01:23And that starts with @media followed by an open and close paren and then the max-width
01:30that I want to test for.
01:32So in this case the attribute of max-width of 768 pixels.
01:37I'm going to go ahead and put curlicue brackets and at first this looks similar to writing
01:41a CSS rule, however, this media query attribute is actually going to be containing CSS rules,
01:49so it might be a little bit different than what you currently used to.
01:52What I actually want to do is create some sort of CSS rule that would allow me to number
01:57one, test this breakpoint, but number two visually actually display on the monitor that
02:03I have reached this breakpoint. We're kind of killing two birds with one stone.
02:06We're actually writing our first media query but we are also building in a testing mechanism on top of it.
02:12In order to do this, we are going to actually create a body element and use the pseudo-class selector of before.
02:19Inside of here I'm actually going to use the content attribute, and I'm actually going
02:22to have a message be displayed whenever we reach this breakpoint.
02:26In this case, I will say Tablet media query (<768px) and then the word fired.
02:35To continue this rule we want to add a font-weight and make that bold.
02:39Next, we want to display it as block. We want to text-align to the center.
02:44Next, we will actually want to go ahead and give us a background color.
02:47This will be an RGBA, and I want to give us actually a transparent yellow color.
02:52The values for this will be 255, 255, 0 and then for the alpha transparency 0.9.
02:57Next, I actually want to position this, and I want to absolutely position it to the top
03:04of 0, a left of 0, a right of 0 and then to deal with any z-indexing or any overlapping,
03:11I will actually want to go ahead and give this a z-index of 99.
03:15Now that we have media rule written, let's go ahead and save this.
03:18Tab back over to our browser, refresh it, and then I'm going to go ahead and resize the
03:23browser until we reach that particular breakpoint. Great.
03:29So our media query has fired.
03:31It's giving me this notification at the top of the page, and we'll be utilizing this throughout
03:35the remaining media query discussion that we have so that we know when each media query is firing.
03:41Let's go ahead and open the browser, back up to the width that was at before.
03:45We notice the media query now disappears because we're back to the browser style sheet that's being applied.
03:50Tab back over to our editor and then let's just copy this, paste it back in and then
03:56let's make the modification here to comment, we will call this Mobile.
04:00Then a mobile breakpoint I want is actually going to be 480 pixels.
04:03I am going to change my content here for the notification to say Mobile media query (<480px) fired.
04:13I'll leave the same color so this way we will actually see the message change. I'll save this.
04:19Tab back over to the browser, refresh, and then begin resizing once more.
04:25We reached our Tablet media query, and now our Mobile media query.
04:33So now we're actually seeing the different breakpoints fired off, and we can utilize
04:38this now for writing additional CSS rules to hide content, to modify content, or to manipulate
04:45content in any manner that we want so that our page layout seems to becoming more responsive
04:51as we add these additional rules.
04:54One other thing I want to discuss, and that is the meta-viewport.
04:57Have you ever browse to a website on your mobile device and notice that you had to double-click
05:01on the screen to enlarge it, or the web page that you are looking at had to be pinched
05:06or squeezed in order to be viewable?
05:09This is an example of a website that is not using what is known as the meta-viewport tag.
05:14If we go ahead and tab over to our browser and inspect the page with the Chrome developer
05:18tools, that's Command+Option+I and then focus in on the head section, we can see an example
05:24of the meta-viewport tag.
05:25It's best to combine the Meta-viewport tag with media queries when considering responsive design.
05:32The meta-viewport tag sets the browser's layout viewport relative to the CSS it is displaying.
05:38This ensures that your site is set to the optimal width determined by the device.
05:43Media queries are a powerful new tool in our Responsive Design Toolbox and properly understanding
05:48how to use it makes all the difference.
05:50We looked at the importance of using the viewport meta tag for making sure our design responds
05:55accordingly in mobile devices and multiple ways to write media queries.
05:59Often when you start writing media queries, you can become quickly lost in all the CSS.
06:04So next we'll discuss the workflow for ensuring our CSS is organized by breakpoints.
Collapse this transcript
Creating a style sheet for each breakpoint
00:00As you progress with the use of Media Queries, you may begin to start having a stylesheet
00:04that becomes hard to manage with the various breakpoints you want to respond to.
00:08At some point it may make better sense to separate the CSS into smaller more manageable
00:13files based on what breakpoints are reached.
00:16We have seen this technique used with the Adaptive.js approach and while JavaScript
00:20is not needed in the Responsive approach, the concept of smaller files may seem to be a good idea.
00:27Let's entertainment that approach and how we would implement it next.
00:30Let's begin by tabbing over to our editor and opening up the css folder inside of our theme.
00:35Go ahead and click back on the layout.css and scroll down to the bottom where we have
00:40entered our media queries previously.
00:42We have two new media queries that we have run, one for our mobile and one for our tablet.
00:47And to better organize these we are actually going to create two stylesheets, one for our
00:51mobile and one for our tablet, and then actually move the CSS code into those corresponding CSS files.
00:59Let's begin by right-clicking on the css folder and saying New Text Document, and we will
01:03call this mobile.css we'll do this one more time and call this tablet.css.
01:12Let's click back on our layout.css file, scroll down to our mobile media query, highlight
01:18it, cut it, and then place it inside of our mobile.css file.
01:21Go ahead and save that.
01:23Click back on the layout.css once again, locate the Tablet media query, highlight it,
01:30cut it, go back to our tablet.css, paste it in place, and then hit Save.
01:35Now we have moved both our mobile media query and our tablet media query into corresponding
01:41CSS files named the same.
01:43This will help us better organize our mobile media queries and tablet media queries as we move forward.
01:50Now that we actually have those in place we need to actually add a CSS reference inside
01:55of the .info file so that we can utilize these.
01:59Scroll down to where you find the responsive.info file, select it, and then locate the stylesheet section.
02:05Currently, we have base, grid, and layout, but we need to add the mobile and tablet to here as well.
02:11I am actually going to highlight the layout.cssstylesheet, paste it in twice, and then the order of precedence
02:18here is very important. We want to be layout, tablet, and then mobile.
02:23So let's go ahead and change layout to say tablet.
02:26Our second one to say mobile. Save this and then tab back over to our browser.
02:31Then the first we need to do is we need log in to flush that Drupal cache.
02:35So go ahead and log in now, /user, log in with the credentials of admin, all lower case, same for the Password.
02:42Once we are logged in, we want to flush the cache, go back to our Home page, and log out.
02:47Because one of the things that's going to happen is once we start resizing this, you
02:51are not going to see message at top because of the fact that we have this Admin toolbar
02:55that's sitting in the exact same position. So log out, now go ahead and resize.
03:04There is our tablet media query being fired. There is our mobile media queries been fired.
03:10If I go ahead and expand the web page back and then open up the Chrome developer tools
03:15and then expand the head section and then locate the stylesheets that are being pulled
03:19in through the Drupal interface, I can see now that my order is base, grid, layout, tablet, and mobile.
03:26Having separated our CSS into smaller more manageable files and naming them based on
03:31the breakpoints we want to respond to, we have made our media query workflow more manageable.
03:37We should've a great grasp on media queries in general and the various techniques we can
03:41use and hopefully you are starting to build upon the workflow.
03:44However, how do we take what we have learned so far and apply this to best practices for
03:49Drupal Responsive theming? Let's take a look at that next.
Collapse this transcript
Understanding media query best practices
00:00Since Media Queries are still just a CSS stylesheet with conditional logic inside it, the
00:05concept of adding it to a Drupal theme is not that difficult.
00:08Yet there are multiple ways to approach adding media queries, we can add to the CSS file
00:13directly like we did previously, we can reference it in our .info file or even through code.
00:20Which way is best for you really depends but we will look at each technique and then talk
00:23about the best practices for making media queries work for you in Drupal.
00:28Let's begin by tabbing over to our Editor and opening up our Responsive Drupal Instance
00:33and then selecting the responsive.info file.
00:37Previously we added references to our mobile and tablet CSS files; however, there are several
00:41other ways that may make managing media queries in Drupal easier. One approach is by modifying
00:47the CSS files to not include the media query attribute at all and then moving the attribute
00:53into the responsive.info file stylesheet array.
00:56This allows you to easily glance at the .info file and see what breakpoints trigger the
01:00different stylesheets inside your design.
01:03Let's begin by opening up the tablet.css file and then removing the @media attribute.
01:09Go ahead and save the file and then select the responsive.info metadata.
01:14For the tablet.css, we actually need to add that break point back in.
01:19So this will be and, open and close paren, max-width, 768 pixels.
01:26Now that we have a reference based off of that breakpoint pointing to our tablet.css
01:31style sheet, we can go ahead and save our .info file, tab back over to our browser.
01:36And then make sure we log in and the first thing you are noticing is the Tablet media query fired.
01:41This is not an error, the reason we're seeing this is because since we were to move the
01:46breakpoint and place it inside of our .info file, currently this is being applied to the
01:51body element for all breakpoints.
01:53This will disappear as soon as we go in flush the cache.
01:56Let's log in now, go to the top for Admin toolbar, flush the cache, log out and then
02:04resize the browser. There is our Tablet media query being fired.
02:08And one thing I want to show you as is once we keep scrolling down we are no longer are
02:11going to see the mobile media query being fired. Let me explain to you the reason for this.
02:16This is called Order of Precedence, one thing to note is that if you prefer this method
02:21that you cannot mix the way that you are calling a response of stylesheets, that add media
02:26attribute cannot be in the stylesheet and in .info file at the same time, in this case
02:32we modified the tablet but we didn't modify the mobile.
02:36So in this case when the stylesheets aren't actually being displayed by Drupal, the tablet
02:40is coming after the mobile reference.
02:42One thing to keep in mind if you choose to use this method for adding media queries is a CSS aggregation.
02:48Drupal will not aggregate these CSS files together into the all stylesheets array.
02:53So if performance is a concern you are better off managing your media queries all in a single file instead.
03:00Our second approach is based on best practices as it will allow for our files to be aggregated
03:06and thus increase the performance of our pages as they load.
03:09Let's begin by placing those files back into a single file that we will call responsive.css,
03:16tab back over to your editor, and inside of the css folder go ahead and right-click and
03:21create a new document. We will call this responsive.css.
03:26What we want to do is actually take the tablet and the mobile stylesheets and place them
03:31together inside of the responsive.css file, let's go ahead and do that starting with the
03:38mobile document, copy, paste.
03:40And then I want to do the same thing for the tablet.
03:49I am going to place this above because we want to fire off in a particular order and
03:53then since I had removed the @media attribute I am going to copy the one from the mobile
03:58and put it around the tablet and make sure I changed my breakpoint, remember it was 768 pixels.
04:05Now that I am managing both my tablet and my mobile stylesheets inside of a single CSS
04:10document, I need to make sure that I make a reference to this document inside the .info file.
04:16Go ahead and tab back over to responsive.info I can actually go ahead and remove the tablet
04:22reference, and I can modify the mobile reference to now point to responsive.css.
04:29Save the document, tab back over to our browser, log in, credentials are admin lowercase, same for the password.
04:37Go ahead and flush the cache and then log back out.
04:41And let's go ahead and resize the browser to test our results. There is the tablet media
04:45query being fired, there is a mobile media query being fired.
04:49One more thing in finishing up that I want to do is I have actually provided to all the
04:53users a cleaned up version of our responsive.info file, and I want to walk through it and explain
04:59to use some of the different things that I have done for presentational purposes that
05:03will assist us as we move along on our series here.
05:06Let's go ahead and tab back over to our Text Wrangler or to the editor of your choice,
05:11and let's locate inside of the 06_04 folder of the file responsive.css.
05:16I am actually going to highlight everything inside of it, copy it and then go back up
05:22to my responsive.css file inside of my Drupal instance and highlight and paste the contents in place.
05:28Let me go ahead and scroll back up the top real quick, and I want to actually explain
05:31to exactly what's going on.
05:34I am going to go ahead and make some comments here with CSS just so I can get rid of some
05:37of the effects that are taken place.
05:39So we can get a visual of exactly what I'm doing with the container element here.
05:43I am going to save this, I am going to tab back over and then I am going to refresh.
05:48Let me go ahead and resize the browser back to the tablet breakpoint, and the minute I do,
05:53you should be able to see the margin about the left and the right snap in.
05:58And this is done for presentation purposes so it's easier for the user to read on tablet device.
06:04Tab back over to the Editor and let me uncomment the header section.
06:09And real quick what I am doing here is I'm actually removing the tagline, I'm decreasing
06:14the font size of our heading for our h1.
06:17And I am readjusting the height and the width of some margins on some different elements
06:23that are inside the header.
06:24Let me save that once again and then refresh the page.
06:27So you can see now the tagline has been removed, some margin and padding has been reduced as
06:31well as the h1 has been reduced, so it's a little more readable now on tablet device as well.
06:36Tab back over to the Editor, and let me scroll down to our mobile section.
06:41Let me go ahead and comment out anything for the containers itself and the header and slider
06:48and feature areas of some other presentational things that I added in.
06:51And then let me save that and then scroll back up to where I am decreasing the body font size.
06:57Let's tab back over to the browser, and you refresh and then move this into a mobile breakpoint.
07:02You can see here we are having some issues with the sliders, which is one of the reasons
07:05why I have hidden the slider.
07:07But what I have actually done here is decreased the body font size.
07:10It's not really easy to see because it will increase by 90%, but as we saw in our previous
07:14video we can modify the body's font size and have that control of the size of the font on the whole page.
07:20Let's go back to the Editor here real quick.
07:22And then let me uncomment the containers, let me comment back out through the heading
07:27section, so we can actually see what's taking place.
07:29Save that, tab back to our browser and then hit Refresh.
07:32Now you can see how things moved in from a three column to a one column layout all the
07:36way as we moved down the page.
07:38So that makes it much more readable any type of mobile device such as a phone.
07:42Let me go ahead and uncomment the rest of this.
07:47Save it tab back over to our browser, refresh, and now we should be able to see that the
07:51slider has been hidden, I have kind of moved some things up with a margin and padding.
07:56I have modified the font sizes, I've made the columns more readable.
08:00So now we have a cleaned up version for both our mobile and for our tablet.
08:05From the simple method of adding a reference to our media query stylesheet in HTML to a
08:09more complex method or referencing through code, we tackled adding media query functionality to our design.
08:15I would recommend that you choose a method that's best for you and at this point are
08:19fix with theme is becoming quite responsive, but how do we go about enhancing certain functionality
08:25for smaller devices such as the menu.
08:27We will go ahead and take a look at that with responsive menus next.
Collapse this transcript
7. Responsive Menus
Introduction to responsive menus
00:00What are responsive menus?
00:02By responsive we mean menus that change according to the device or screen size.
00:07This could mean different styling, different positioning, or a completely different layout
00:11that makes it easier for the end user to navigate the site.
00:15Why would we care about making our menus responsive, though?
00:18For one, as your screen size gets smaller the actual interaction with navigation becomes more difficult.
00:25Let's take a look at some examples of sites with responsive menus and one that doesn't,
00:30and you can make the decision yourself on which is best.
00:33Let's start with our site to begin with, because our site does not have responsive menus at all.
00:38In fact, if we begin to resize our browser our menus do shrink down.
00:43But once we get to a certain point they kind of blow up our design.
00:46We will go ahead and take a look fixing that a little bit later on.
00:50But how about we look at some different examples of great responsive menus.
00:55Let's go ahead and browse on over to foodsense.is and take a look at their menu structure.
01:01Their menu starts off on the side, but as I begin to shrink their browser and hit different
01:05breakpoints, you'll notice that the menu goes from the sidebar, to the top with some iconic interactions.
01:12And then if I continue to scroll it down the icons disappear.
01:16And eventually once I hit my mobile breakpoint the menus go all the way to the top.
01:21Let's take a look at another example, smashingmagazine.
01:24smashingmagazine actually has two different menus.
01:27They have their main menu on the side and then have a categorical menu up top.
01:31Let's go ahead and start resizing and see what happens.
01:34Automatically we can see the sidebar main menu jumps to the top.
01:37As I continue to scroll down we see that the menu then jumps back to the side, and once
01:42I hit the tablet breakpoint I get a jump menu, both menus are combined into this, and this
01:47makes it much easier on a tablet or a mobile device to actually select the navigation.
01:53Let's that a look at one more example.
01:56Microsoft recently launched its new homepage, and as we resize the browser we will notice
02:01that the menu structure once we hit a particular breakpoint turns into an icon all by itself
02:07and then when I click on it I have the menu in a dropdown list.
02:11These are all three great examples of responsive menus.
02:14We discussed what responsive menus are and why we should consider them when developing a responsive design.
02:20We had viewed examples of websites without and some great examples of websites that use them.
02:25But exactly how do you develop responsive menus, let's take a look at that next in Drupal 7 Responsive Design.
Collapse this transcript
Creating a responsive menu
00:00Understanding what responsive menus are and why you should use them are one thing.
00:04But actually making responsive menus is another.
00:07There are multiple different visual aspects, navigational considerations, and different
00:12menu types to choose from.
00:15Let's begin by taking a look at our standard menu and how we would go about modifying it
00:19to be more responsive with just a little CSS.
00:23The first thing we will tackle is the mobile navigation.
00:25I want to start off with a pure CSS technique and the styling to have our menu look good
00:30in the mobile breakpoint is very simple.
00:33Let's begin by tabbing over to our editor and then looking for our
00:36Drupal/drupal.responsive/sites/all/themes/responsive folder, and then inside of here, our assets/css/responsive.css stylesheet.
00:48Go ahead and scroll down to the mobile breakpoint, and then into our header section, and we are
00:53going to add a CSS declaration for our header with a class of nav.
00:59Inside of here that element is currently floating.
01:01Let's go ahead and tell it not to float.
01:03Let's save this, tab back over to the browser, size it down to our mobile breakpoint, go ahead and refresh.
01:10We can see that now it's actually not floating.
01:13It's flushed to the left. However, we are missing a menu item.
01:16It's actually off the page, and it's not being displayed.
01:19That's because either the font size or the padding is causing it to not flow with our document.
01:25Let's take care of that.
01:27Tab back over to our editor, and that's inside our header element, inside our menu item that
01:32has a nav, and it's an unordered list with list items, and that's our anchor elements.
01:38Let's go ahead and modify the font size, and let's also take care of the padding 10 pixels by 16 pixels.
01:44Let's save that, tab back over, and refresh. Now we are looking a lot better.
01:49However, what happens when we look at our tablet breakpoint.
01:53Things don't quite flow on the page as we would like them to.
01:56So let's actually go ahead and tab back to our editor and take a look at how we would
02:01actually modify our menu for the tablet breakpoint.
02:04I am actually going to copy the CSS declaration, scroll back up to my tablet breakpoint, paste it in place.
02:12I am fine with the font size, but the padding needs a little bit of help.
02:15So I am actually going to reduce it down to 4 pixels by 10 pixels, save the page, go back to my
02:23browser, and let's go ahead and scroll this until we hit the tablet breakpoint. Refresh.
02:32That looks a little bit better.
02:33Now we actually have lost the tag line and our menu items actually shrunk down a little
02:38bit so it looks more in line with the current page.
02:42Simple but elegant a little CSS with media queries can go a long way.
02:46Taking our understanding or HTML and CSS and applying these techniques we were able to
02:50create a nice, but simple looking responsive menu.
02:53But exactly how do we apply some of these other techniques that we saw to Drupal and
02:58are there any tools to help us in making the transition?
03:02Let's discover those techniques next.
Collapse this transcript
Integrating responsive menus into Drupal
00:00Integrating responsive menus into Drupal can vary from simple to challenging depending
00:05on your knowledge of CSS, jQuery, and Drupal modules.
00:09We are going to tackle another one of his approaches by taking a look at common menus
00:13in Drupal and at how with the little tiny jQuery script we can make it more responsive
00:17for our users on various screen sizes.
00:20This technique will be integrating jQuery into Drupal utilizing a module to convert
00:24our menu to a dropdown list.
00:27In the case of mobile jump menus we are lucky that Drupal 7 has a module for just such a script.
00:32Let's go ahead and browse on over to drupal.org/ project/tinynav, scroll down to the bottom, and then click
00:40on the Download for the zip file.
00:42Once the download is complete go ahead and open up your Downloads folder and then extract the file.
00:48Copy it to our desktop Drupal/drupal.responsive/ sites/all/modules folder.
00:57Once we have that in place let's go ahead and tab back over to our Drupal instance and log in.
01:02From here go ahead and put in your user credentials admin, all lower case.
01:07Once you're logged in we need to actually enable the module.
01:10So navigate to Modules and then scroll down until you find Tiny Nav js.
01:17Enable it, click on Save configuration.
01:20Now that the module has been enabled, we need to actually finish configuring it, click on
01:25Configuration, and then under User interface tinynav.js.
01:30Then we need to put in the CSS jQuery selector that will target our element that we want to convert.
01:36In this case it's .nav ul.menu.
01:41Next thing is what media breakpoint do we want to target this for.
01:45We want to target this for our mobile breakpoint.
01:47So we are going to change that to 480, hit Save configuration, and then go back to our homepage.
01:52Let's go ahead and log out so we can see a cleaner look of this and then resize the browser
01:58back to our mobile breakpoint.
02:00Go ahead and hit Refresh, and now we see our menu has been converted to a jump list.
02:05From CSS to jQuery to Drupal we have explored how to best integrate responsive menus into our Drupal design.
02:13The choice is yours as to the best approach and often your design will dictate which choice to make.
02:18While you may think that we're done with making your Drupal design responsive, there are often
02:22a few items designers forget about. How about tabular data?
02:27While we don't design layouts with tables anymore we still have cases where we need
02:31to display tabular data.
02:33How about responsive tables? Let's explore that next.
Collapse this transcript
8. Responsive Tables
Introduction to responsive tables
00:00You may be thinking to yourself why should I worry about tables being responsive?
00:05Aren't they already responsive? They grow and shrink as needed. True and false.
00:11Table cells can only shrink down so much before the content wraps and then they eventually
00:15stop shrinking altogether. So how do we fix this?
00:19Responsive tables are tables that allow for different screen sizes without sacrificing
00:23the data being displayed in the table.
00:26This reason alone is why we should use them in our design.
00:29Let's take a look at non-responsive tables in a responsive environment so we can have
00:34a better understanding of how this works. Let's begin by navigating over to resources.
00:39Here I have some tabular data.
00:41Let's begin resizing the browser and see what happens.
00:44Fair enough, our table seems to respond just fine. Or does it?
00:48As I shrink the browser down you can see that the table cells content becomes squished and
00:53imagine if you were actually trying to look at this table inside a mobile device.
00:58A responsive table, however, would allow you to ensure that the most important data is readable.
01:03Columns where the content would not become unreadable or squished.
01:06The ability for the table to more from a tabular layout to a more familiar layout.
01:11Now that we understand what responsive tables are, though, what is the importance of using them?
01:16How we go about creating them?
01:18Let's take a look at some different techniques for making sure our tables don't lack the
01:21responsive quality they deserve next.
Collapse this transcript
Creating responsive tables
00:00I know you're thinking, "All this trouble over a couple of tables?"
00:04But I say a table should not be treated any differently than other content when it comes to responsive design.
00:10Just like responsive layouts where we can hide or move content, we can do the same with tables.
00:16The Unseen Column, Flip Scroll, and No More Table Techniques are just a few that are out there available to us.
00:22And with a little bit of knowledge of CSS, we will be able to walk through the next one, the Unseen Column.
00:29This content maybe hidden to you because there's no navigational menu item out for this.
00:33So, make sure you go ahead and browse now over to drupal.responsive:8082/unseen-column,
00:41and you will be on the page that I am looking at currently.
00:44This is a table that we will be dealing with.
00:46And it has a div tag wrapped around it with the ID of unseen.
00:50You could change this to any ID or class name you want, just as long as you target the correct elements in our CSS.
00:57Let's go ahead and resize the browser and see what happens.
01:00Currently nothing. Everything gets squished just like we're expecting.
01:04However, with this technique that we're about to do, we are actually going to be able to
01:08hide or show particular columns that when our real estate becomes smaller are more important to the end user.
01:17This will make it easier to navigate, or look at the data that's in this table at smaller resolutions.
01:23In order to do this, let's go ahead and open up our editor, open up the
01:26Drupal/drupal.responsive/sites/all/themes/ responsive/assets/css/responsive.css.
01:36We're going to target both the tablet and the mobile breakpoints.
01:41And since there is a lot of CSS to write, and it might look I actually mistype something,
01:47let's go ahead and copy this from the Lessons folder that's provided to everyone.
01:51I have made notes in here for us, take a look at.
01:54The first is Add to Tablet Breakpoint in Responsive.css.
01:58Let's go ahead and copy this, tab back over to our editor,
02:00and inside of the tablet, let's scroll down to the bottom and paste it in place.
02:06Go back over to our Notes, copy the Mobile Breakpoint, go back to our editor, scroll
02:12down to the bottom of our mobile breakpoint, and paste it in place.
02:15Do a little housecleaning here just so we have better formatting, save the document,
02:21tab back over to our browser, refresh, and let's try resizing again.
02:26And you see what's happening.
02:27The Company column drops out, and now I am down to Price, Change, Change%, Open, High,
02:33Low, Volume, and watch as I keep going down what happens.
02:36Now, I am down to five columns.
02:39Now, this technique is used with hiding the different columns in the table.
02:44And it's done by a child selector.
02:46In this case, we actually have to know which column it is that we want to display as none,
02:53or in the case of the opposite, if we actually wanted to display a column that might be hidden
02:56by default, we would have to know what those columns are.
03:00Let's go ahead and tab back to our browser and actually pull this back out to full-size,
03:04and let's count the columns that we have, 1, 2, 3, 4, 5, 6, 7, 8, 9.
03:11Let's say that we actually want to hide one of these other columns. Tab back over.
03:16Let's say we want to hide the 9th column.
03:17I am going to change the 8 here on the nth-child to 9, save our work, tab back over, that's the Volume column.
03:23So if I refresh the page, and I begin resizing the browser, once we hit that breakpoint,
03:30the Volume column drops out.
03:32So hopefully now, you get the idea that this nth-child relationship has to do with the
03:37columns that you're wanting to hide or show.
03:40This is great for tabular data that we actually have a lot of control over.
03:44But it's not realistic when it comes to Drupal.
03:47Drupal can provide us tabular data either by somebody adding it into the content area
03:51of a node or through Views.
03:54What if we want to be able to have all the tables be responsive?
03:58This next approach is by ZURB, and they are the ones that created a technique that will
04:03allow for tables to scroll their content using a little jQuery and some CSS.
04:08Tab back over to your browser, and then open up zurb.com/playground/responsive-tables.
04:16We are going to go ahead and start this by scrolling down and clicking on Download the Code.
04:21With the zip file downloaded, go ahead and open up your Downloads folder and extract the file.
04:26There is only two files that we actually need inside of here, the responsive-tables.css,
04:32and the responsive-tables.js.
04:35Let's go ahead and copy each one of these to the respective folders, starting with the CSS.
04:40Select the responsive-table.css, copy it, go back to our desktop, and open up our
04:46Drupal/Drupal.responsive folder, and then our sites/all/themes/responsive/assets/css folder.
04:55Paste that in place.
04:56Now, let's go back to our Downloads and grab the JavaScript, copy it, go back to our desktop,
05:03and this time I want to put it inside of my js folder and then inside of my library.
05:09Go ahead and paste that in place.
05:10Now that I have both the files exactly where I need them, we need to be able to configure these to work.
05:15Go ahead and close the folder, and let's go back to our Drupal instance.
05:20From here, let's actually go ahead and click on Resources.
05:22And what I want to do is I actually want to apply this technique to our table that we have here.
05:28Let's go ahead and log in real quick, /user, admin.
05:34Once we are logged in, we can go back to Resources and then click on Edit.
05:39Inside the WYSIWYG here, I have a table. Let's go ahead and click on Source.
05:42And then for this to work, I actually need to be able to add a class to the table with
05:47a class name of Responsive.
05:49Let's go ahead and select the table and say class="responsive", save this.
05:55And now we have our table set up to use this.
05:58We have a couple of more configurations, though, that need to take place first.
06:02So, tab back over to our Editor, and next thing that I need to do is go into my responsive.info file.
06:08From here, I need to make reference to both the CSS and the JavaScript.
06:12We will start with the CSS.
06:14I am going to copy that current line, paste it in, and just change this to say responsive-tables.css.
06:22And in fact, actually it's tables, plural, so make sure you don't make that mistake,
06:26otherwise you will not see the effect take place.
06:28Next, I need to do the JavaScript.
06:30The JavaScript is inside the Libraries folder, and it is called responsive-tables.js.
06:37I am going to go ahead and copy one of my script lines here, paste it in.
06:40And since it's inside the library, I can go ahead and change this to say responsive-tables.js.
06:47Let's go ahead and save this, tab back over to Drupal, and flush the cache.
06:52Now, if I begin to resize the table, you can see the effect take place.
06:57It adds a scrollbar here so that my left column stays static, but it allows me to be able
07:03to better read the content without it becoming squished.
07:06That's a miracle what you can do with CSS and a little elbow grease.
07:11We walked through two different techniques for handling tabular data and responsive design.
07:15Each has its own unique approach with jQuery and CSS.
07:19And anything in responsive design, there is often more than one way to approach it.
07:23Let's wrap up Responsive Tables by integrating some of these techniques into Drupal 7 with Views.
Collapse this transcript
Integrating responsive tables into Drupal
00:00When you think about in Drupal, you may not always think about tabular data.
00:04But in general, there are only two places you may have tabular data to work with.
00:08The first is the end user, creating tabular data using the WYSIWYG inside a node or a
00:13block, the other is the output of the view of data from various content types.
00:17In this section we will cover tabular data in views and how to modify the HTML for our
00:22needs so that we can apply the responsive table's techniques we learned in the previous movie.
00:27To begin with, I am already logged in, but if you need to log in, do so at this time and
00:32then go ahead and navigate over to Structure and Views.
00:36In order to do this technique, I actually need to create a view first.
00:39so I am going to go ahead and click on Add new view, I am going to give this View a name
00:43of tables, and then this is going to be a Content Of Type All.
00:47I am going to create a page called tables with the Path of tables and the Display Format
00:53is going to be Table of fields.
00:56From here I am going to click on Continue & edit, and right now if I scroll down all
01:00I have is a table of the Titles of the content that is currently inside my Drupal instance,
01:06I want to add a couple of more columns.
01:09Let's go to FIELDS, click on add, Filter the Content, and let's look for the Author uid.
01:16We'll go ahead and select that click Apply, leave the defaults and click Apply (all displays).
01:22Now if I scroll down I have two columns of data. Let's go ahead and add one more column.
01:27Scroll back up to FIELDS, click on add, Filter the Content, and this time let's look for
01:33let's say the Last comment author.
01:36Go ahead and select that, click on Apply (all displays), Apply (all displays) again, and
01:41now I should have three columns of data. That works for me.
01:44Go ahead and scroll back up and click on Save.
01:47Now that I have a view that has tabular data in it, let's go ahead and browse to that page
01:52real quick and see what we have.
01:54Remember, this is called tables, so if I go to the tables page--here you go--I see a table
01:59of tabular data on this particular page,
02:02and if I go to resize it, I am back to the squishy squeezed-in problem that we have with most tables.
02:09Let's go ahead and open up the Chrome developer tools, let's go ahead and inspect the table,
02:13and if we notice here we have this class of views-table cols-3 which may help us while
02:20doing some theming; however, I need to be able to put the class of responsive on here, and
02:26currently the only way to do this is by actually creating a views template. Let's take a look at how to do that.
02:32Go ahead and close the Chrome developer tools, let's go back to Structure > Views, click
02:38on and edit for our tables view, and then over on the Advanced tab if I expand that and scroll
02:44down I see a section called Theme, and if I click on Information, this shows me the
02:50output of the theme for this particular view, and I can modify these by creating copies
02:55of these either with the default view names that are specified in bold or by creating
03:00any of the view names here that I have.
03:03This particular time, I am going to want to create a template for views-view-table.tpl.php.
03:09Let's see how we would go about doing that.
03:13Go ahead and close this, and let's go ahead and tab over to our editor real quick, and
03:18I want to show you something.
03:20Inside our theme we actually have a templates folder, and these are some of the templates
03:24that were set up just for demonstration purposes for this series.
03:28If I expand views, I can see that I already have some templates in there, but I do not
03:32have one for views-view-table, so how do I know exactly what goes inside that?
03:39Well, if I scroll up to sites/all/modules and expand the modules folder and then the
03:44views folder and then look under theme, I can see some default templates that I can
03:50use, and one of them is actually views-view-table.
03:53I am going to open that, I am going to copy the contents, I am then going to close the
03:58folder, close the views folder, close the modules folder, go back to my templates, right-click
04:03on views, and say New Text Document. I need to call this views-view-table.tpl.php.
04:15With that created, I am going to copy the contents from that other view and then paste it inside of it.
04:21I'll go ahead and hit Save and then scroll up and take a look at what we have.
04:26This says this is a template to display a view as a table, and I can actually see the
04:31table and some classes that are being used.
04:34For demonstration purposes, I really don't care about these other classes that are being
04:38applied, so I am actually going to remove this, and then I'm actually going to hand code
04:43class="responsive" similar to what we did inside the WYSIWYG.
04:49However, this time I am going to save it, and if I tab back over to my browser, flush
04:54the cache, and then browse back over to that page, open up the Chrome developer tools real
05:00quick, and let's inspect this table.
05:02Now I have a table with a class of responsive, and the nice thing about using the template
05:07in method is any view that I create, that I choose to use as tables, will now have this
05:13class, and with that previous technique that we learned, all the tables will now be responsive.
05:19Let's close the Chrome developer tools, resize this, and see what we get.
05:23There is our scrollbar for our content, there's a scrollbar for our column if our column has
05:28information in here that's too wide.
05:31Responsive tables do not take a lot of work to accomplish, but we need to make sure we
05:35don't overlook them when designing in Drupal.
05:38Knowing how to modify the HTML output and then apply the appropriate CSS or jQuery is just
05:43a small task to ensure that our Drupal 7 design is responsive.
05:48One more thing we want to take a look at before we can be proud that our Drupal design is
05:52completely responsive is forms. Let's take a look at responsive forms now.
Collapse this transcript
9. Responsive Forms
Introduction to responsive forms
00:00You may be asking yourself, what are responsive forms and why should I use them?
00:05Well, responsive forms are forms that adjust to the user's screen size and allow for maximum input.
00:11Meaning that on smaller devices the input areas are large and buttons are easier to select.
00:17Don't you hate when multiple text boxes or buttons are so close together that selecting one is almost impossible?
00:24If you answered yes, then designing responsible form should be part of your workflow.
00:28Let's take a look at an example.
00:30I have open in the browser the smashingmagazine.com contact page.
00:35Our friends at Smashing Magazine have a really well- designed responsive site, and their contact form is as well.
00:41Let's give it the browser resize test and see what we get.
00:44I am going to scroll down to where I actually see the form and then I am going to grab the
00:48browser and start to resize it.
00:50You can see as it hits the different breakpoints it shifts into different positions, but the
00:55form itself always remains readable.
00:58The things that I want to focus on are, number one, label placement.
01:01A lot of times in browser-based designs you will see label placed to the side of the import
01:06or form control, and that just doesn't translate to mobile.
01:10The label placed to the side of the input does not allow for the input itself to be
01:13as wide as needed and often makes entering content a chore.
01:18Smashing Magazine places the label above the input control, making it more readable and
01:22allowing for the input controls to occupy more space.
01:26This works really well in all breakpoints. The next thing I want to focus on is inputs.
01:32Oftentimes form development is a forethought and input elements are just left at their
01:36default size, making it hard to select them when dealing with forms that have more than one input.
01:41In the case of Smashing Magazine, the input is large enough to easily select an enter content
01:46info regardless of its state. How about sizing? The third thing is the widths of the controls.
01:53This relates to the label placement a little bit in that if the label is placed above
01:57the input, the input itself needs to be able to be as wide as its container to allow for
02:02that maximum amount of content. There is a small issue here, though,
02:05in that input and text area controls still have attributes that can control their size
02:11and don't really behave like we would expect most block level elements to behave.
02:15Adding a width of 100% of forms doesn't always work either, once you begin adding margin and padding.
02:21The last thing I want to focus on is the input types themselves.
02:25Too often we just leave the default type to text. How is that a bad thing?
02:30Well, think back to the mobile device, would you prefer to get the correct keyboard prompts
02:35or hunt and peck your way around to enter emails, phone numbers, or URLs?
02:39We need to think about how devices can utilize these new input types.
02:42The worst thing that will happen is it will default back to the text input type in browsers that don't support them.
02:49Now that we've taken a look at an example of a great responsive form and appreciate
02:53why they should be used, we need to understand exactly what makes a good responsive design
02:57for forms and some of the different techniques used to ensure that users are not yelling
03:02at you the next time they fill out a contact form or register for an event.
03:07Let's move on to that next.
Collapse this transcript
Creating responsive forms
00:00Most of us have created a form or two, but the design has been strictly focused on the browser.
00:05Yet, how many times have you viewed a form on smaller devices and just wanted to scream?
00:10I can't click on the correct button, the form is too hard to read.
00:14Why don't I get the proper keyboard keys for entering my email?
00:17Well, the answer is simple and the solution even easier, using the right elements, the
00:23proper CSS will help us in creating responsive forms that not only look good but function just as well.
00:31I have open in a browser a standard contact.html page with a working form.
00:37As you can see, this is a perfect example of a non-responsive form.
00:40It has all of the previous characteristics of a standard form that we talked about previously.
00:45Giving it the browser resize test, we can see that the labels are placed to the side the
00:49input elements are too close to each other, they're not wide enough to see the content
00:54you are entering, and form controls break out of their parent containers.
00:58No worries, we're going to fix all of that right now, starting with the labels.
01:03Let's begin with tackling the issue of label placement.
01:06Labels by default are in-line elements, which mean they only take out the amount of space
01:10that the characters represent.
01:12However, we can force labels to display above their inputs with one simple CSS rule.
01:18Let's go ahead and open up the editor and take a look at what we have.
01:22Currently I have labels for each of my input elements, and if we want those to actually
01:27display above, we need to actually add a CSS rule for them.
01:30So in our style editor I am going to go ahead and create a label, and I am going to give
01:34this a role of display: block.
01:36I am going to save this, tab back over to the browser and Refresh. Great.
01:41We now have our label displaying above our input elements, and it is now making our page more readable.
01:47But how about those inputs? There are several things I want to tackle with these.
01:52One is the type attributes, two is sizing, and third is the width on them.
01:57Let's go ahead and tackle the types first.
01:59For this particular form, we will modify the type attributes for our email input to actually
02:04be an email field, and this will allow for the correct prompts when viewing it on a mobile device.
02:09Tab back over to our editor, locate the input for email, and currently it's the type of text.
02:15This is a simple change, just change text to say email.
02:19The next one I want to take look at is the URL for websites.
02:23Again the type is text, but we can change this to the new URL type as well.
02:28Now our email and our website, even though we can't see it currently, but if we were
02:32to actually look at this in a mobile device, we would get the correct prompts.
02:37How about placeholders? It'd be nice if I knew exactly what to put into the field and
02:42have a label telling me, well, email, website, but ACTP or www, how about something to prompt me?
02:51You may have seen this technique done with JavaScript or some other method, but we now
02:56have the placeholder attribute that we can use that will give us the same effect.
03:02Tab back over to our editor, and let's go and scroll back up to name, and let's go ahead
03:06and give this a placeholder.
03:08The placeholder takes a value, and this is what's actually displayed in the text box.
03:12So in this case we're going to say Please enter full name.
03:16Save it, tab back over to our browser and Refresh.
03:20Now we can see a placeholder, and when I put my cursor and then start typing, the placeholder
03:24disappears, and if I have to back out, the placeholder shows back up.
03:28Let's go ahead and do this for email, website, and subject.
03:33Tab back over to our editor and then make this a little bit faster, I am just going
03:36to copy this, place it in and say Please enter email.
03:40Again, you can put whatever text you'd like in here that you want to have displayed to the end user.
03:46Let's go ahead and save this, tab back over to our browser and Refresh.
03:51Now we have our labels above, and we have the correct input types, and we have some placeholders.
03:56Next, since we want our inputs to have the maximum widths that the form will allow, we
04:01are going to want to apply the following CSS rule, and that's width: 100%.
04:06And that way our form elements will actually take up the full width of the container.
04:11Tab back over to our editor, scroll on up to the top and then let's go ahead and add
04:15a CSS rule for our inputs.
04:18First input I want to deal with is a type of text, and we're going to say width: 100%.
04:24Save that, tab back over and Refresh, and that takes care of two of my fields.
04:29However, remember since we changed the type from text to email and text to URL, we need
04:34to go ahead and tackle those next.
04:36Tab back over to our editor, and I am going to copy this, add a comma, paste it in and
04:42say email, add another comma, change text to say URL, save this, tab back over to our browser and Refresh.
04:50We only have one more thing to take care and that's our text area.
04:54Tab back over, add a comma and say textarea, save it, Refresh our browser, and now all
05:01of our form elements are taking up as much width as they possibly can.
05:06You may be thinking to yourself, well, they are currently breaking out of the container.
05:09Let's don't worry about that right now. We'll focus on that here in a second.
05:12The other thing that I want to do, though, is add some margin and padding as well as increase
05:17the font size that's inside each of my elements here so that it's easier for me to input content for the end user.
05:24Tab back over to our browser, now we're going to add on to this by saying margin, and we're
05:29going to give this a margin of 6 pixels for the top, 0 for the right, 10 pixels for the
05:36bottom and 0 for the left.
05:39Next I want to add some padding, the padding is going to be 8 pixels by 4 pixels, and finally, the font-size.
05:46Now the font-size is arbitrary. I've given it a font-size that to me looks good with
05:51the current display that we are actually looking at.
05:53So, I'm going to give it a font size of.85 ems. Save this, tab back over, and then Refresh.
06:00Now our display is becoming a little bit more readable and on mobile devices it will be
06:04much easier to actually input content and to direct the end user on what they need to enter.
06:10We still see that we have an issue with our input controls breaking out of the container.
06:15Previously, we had talked about input controls breaking out of their form elements.
06:18To address this issue and control the flow of the form element, we have wrapped a div
06:22around each input element and its respective label.
06:26Tabbing back over to our editor and scrolling down to the actual markup we can see an example
06:30of these div elements wrapped around the input and labels.
06:34Since the div is a true block level element that can only be controlled through CSS, it
06:39doesn't suffer from the size, rows, or column attribute issues that our inputs and text areas suffer from.
06:47Knowing this, we can apply padding and margin to the div container and force the form elements
06:52to contain to its sizing.
06:55Scroll back up, and let's go ahead and add a div CSS rule.
06:59We're going to go ahead and give this some margin of 0, 15 px, and a padding of 0 and 5 px.
07:07Let's save this, tab back over to our browser, and Refresh.
07:11We can see now that we're no longer breaking out of the parent container, and if I do our
07:15browser resize test, you can see that the form elements stay within the content section.
07:21For those CSS gurus out there, you may have been asking why not just use the new box sizing rule?
07:27Well, let me show that off real quick and then I'll let you know why I chose not to use it.
07:32Tab back over and for the inputs I am actually going to add in box-sizing and set it to border-box.
07:40I am then going to quickly comment out the div element, save it, tab back over, and Refresh,
07:47you can see that I am still contained within the content area; however, I've lost some of the padding that I want.
07:51That's not a big issue, I can actually add additional padding now into those input controls.
07:56However, the reason I chose not to use this is because if you need to support older browsers,
08:01you are out of luck.
08:02So make sure you choose the method that works best for the browsers you need to support.
08:07Visually and functionally, our forms are now completely responsive.
08:11We looked at browser versus mobile layouts and how you use CSS to our advantage and have
08:15a better understanding of the correct HTML elements to use when considering responsive design.
08:22Moving on, let's apply these techniques within Drupal and see how we would integrate this
08:26into our workflow in creating responsive forms.
Collapse this transcript
Integrating responsive forms into Drupal
00:00When I think of forms in Drupal, the first thing that comes to mind is the contact form
00:04or the web form module.
00:06Since I want to have a little bit more control over the form, we'll be taking a look at the
00:10web form module in more detail.
00:12Let's begin by viewing the output of our form and then discuss some various techniques that
00:17we learned in the previous section to make it more responsive using CSS, HTML5, and Drupal theme functions.
00:24Let's begin by browsing to our Drupal instance and then navigating to our contact page.
00:29If we give it the browser resize test, you will notice that our form elements break out
00:33of its parent container, and the sidebar will seem to be overlapping the content area because of this.
00:40Let's fix our form to be more responsive like we did in the previous example by tabbing
00:43over to our editor, and opening up the layout.css style sheet inside our theme, and then locate
00:49the Contact section of our CSS, opening up the Editor, browsing to
00:55Drupal/drupal.responsive/sites/all/themes/ responsive/assets/css and then layout.css.
01:03You may have to scroll down the page a little bit to find the Contact section.
01:07Once there, go ahead and hit Enter a couple of times so that we have some room to work.
01:11Let's begin by formatting our input controls.
01:14We want to set their Width to 100%, adjust their Margin and Padding, and set a Font Size.
01:19In fact, we could use the styling from the HTML example in the previous movie, but we're
01:23going to go ahead and do it by hand.
01:25First, though, let's tab back over to our browser and open up the Chrome developer tools and
01:30see what we need to target.
01:32You can either do Command+Option+I, or you can right-click on the element and say Inspect.
01:37What we're going to target is the form that has a class of webform-client-form, and then
01:42the different types of inputs that we have. Tab back over to our Editor.
01:47Let's go ahead and enter CSS declaration for the webform-client-form with an input type of text.
01:53Now that we have that in place, let's go ahead and add our CSS rules.
01:57The first rule is going to be for Width. I am going to set that to a Width of 100%.
02:00Next, we are going to add some margin, and we are going to have a margin of 6px 0 10px 0;
02:08and then some padding. And the Padding previously was 8px by 4px.
02:15And then finally the font-size, we're going to give this .85ems.
02:20Let's save this, tab back over to the browser, close the Chrome developer tools, and then hit Refresh.
02:27One thing to notice here is our input types have now stretched out to the boundaries of
02:31the container, but the website one which we thought was a URL field previously also stretched.
02:37The web forms module actually does not have a URL field currently.
02:42So, we could add this into the CSS which I am going to do just so that once it is added,
02:47it will work properly.
02:48But I wanted to make sure that you are aware of that and then wonder why that field had expanded.
02:53Let's go ahead and target now the email field. I am going to tab back.
02:56I'm going to copy this line, add a comma, paste it in, and target the email field, another comma, paste it in.
03:05We'll target the URL field.
03:06So once they do have that, it will work properly.
03:09I'm going to do comma one more time, and this time I'm also actually going to target the text area.
03:14Now that I have the widths, margin, padding, and font-size for my input controls set the
03:19way that I want them, I am going to make sure I save, tab back over, and refresh.
03:24Now, these may look like they are bouncing up to the edge of the page properly, but they're
03:28actually overlapping a little bit. Let's take a look at that.
03:30Let me go ahead and inspect, and you'll see here that it overlaps just a little bit.
03:35So, even though if we try to do the browser test by resizing the page, the sidebar actually
03:40would drop down before it overlapped, but we do have a little bit there.
03:44So, knowing that, let's go ahead and tab back over to our editor, and this time, we actually
03:50want to target the container itself, to make sure that we lock it in to the constraints
03:56so that we don't have any of those input controls overflowing.
04:00What we want to target here is the webform-client-form once again.
04:03Let me go ahead and scroll up a little bit so you can see it better, and then type in the webform-client-form.
04:10And then in this case, I want to target anything that has a class of webform-component of a text field.
04:17I am going to add a comma. I am going to copy this line, paste,
04:22and this time I want to change text field to be email.
04:25I'll show you where I'm getting this information from here when we go back over to the browser.
04:28I am going to paste one more time, and then I want to target the text area.
04:32Let me go ahead and add the CSS rules for this, in this case, margin of 0 15px 0 0,
04:41and a padding of 0 5px 0 0.
04:44I am going to save this, and I'm going to tab back over and show you exactly what we're targeting.
04:50I'm going to refresh the page, and then if we actually take a look, each of our input
04:54controls were wrapped with a div.
04:56So what I was doing is actually targeting the div.
04:58So in this case, you can actually see that form of the class of webform-client-form and
05:02then our divs with a web form component, text field, email, and text area.
05:07Now, if I close the Chrome developer tools, you can see that the page is starting to look a lot better.
05:13But how about our placeholders?
05:15Since we're using web forms, let me explain to you how they work and how we can modify
05:19their output to add the placeholders to our inputs.
05:21Go ahead and scroll back up, and then what I want you to do is actually log in real quick.
05:26So /user, user name of Admin, password of Admin, log in, go back to the Contact page,
05:33and then up at the tabs you are going see View, Edit, and then Webform.
05:36Go ahead and click on Webform. These are the actual fields that we have.
05:41And if I want to edit a field, I simply click under Operations the text for edit.
05:45Now, I can see where I can give it a Label, I can give it a Field Key, which is for Drupal.
05:50I could give it a Default Value, and why we might want to think about using that as our
05:54placeholder, the only problem with it is it won't disappear when the input has focus.
05:58So currently, there is no way to add a placeholder.
06:02Well, there actually is, and this is for you PHP gurus out there.
06:05We are going to dive into the template.php file, and I'm going to show you actually
06:10how to override or alter the form controls that are being written by Drupal.
06:15Let's go ahead and go back to the View, scroll up.
06:18This way we can actually see the placeholders once they get put in place, tab back over to our Editor.
06:24And what I'm looking for us to do is actually click on template.php, scroll down a little
06:29bit, and we're actually going to add a function.
06:32This function is actually going to be called responsive, which is the name of our theme, _form_alter.
06:40We're altering the form. This takes some multiple attributes.
06:44Number one is the form variable, next is the form_state, and finally the form_id.
06:50Let's go ahead and open and close our function.
06:52And then previously we saw about using that KPR function.
06:56We're going to use it here, too, so that I can show you the form output.
06:59So, we're going to type in kpr(), and then I actually want to take a look for the form_id
07:06that we'll be targeting.
07:07I'll put in form_id, put a semicolon in to close that, and then tab back over, and then
07:13I'm going to have to scroll up real quick and then hit Refresh.
07:16I see here I want to target webform_client_form_9.
07:19So, knowing that, tab back to our editor, and we're going do a conditional statement.
07:26What we are going to say is if the form_id is equal to webform_client_form_9, then go
07:39ahead and do something. Well, what we want to do?
07:42Let's go ahead and output another KPR function, and this time actually look at the form variable.
07:46I'm going to comment out the KPR function above, save it, tab back over, and then Refresh.
07:51Now, we can see at the array that we need to work with.
07:54If I expand this, what I'm actually looking for is the form submitted, and then in here
08:00I can actually see the different fields.
08:02So, I need to be able to target each one of these fields and add a new attribute to it of placeholder.
08:08Tab back to our Editor. We can comment out this KPR function.
08:12Then what I want to do is actually create some placeholders.
08:15So we're going to target the form, the submitted array, the name field, and I want to add
08:25to the attribute, and the attribute that I want to add is placeholder, and I want to
08:27set that equal to whatever I want the placeholder to say.
08:31So in this case, Please enter full name.
08:33Go ahead and close that, save it, refresh the page.
08:38And now we see the placeholder.
08:40I want to actually type in, you'll see that it actually disappears, and when I back out, it comes back in.
08:45I am going to go ahead and let you do the remaining ones, and then we'll be right back.
08:50Now that we have those completed, let's go ahead and save our work, tab back over, and then refresh the page.
08:57We now see our placeholders are all completely done.
09:00While the HTML output of Drupal 7 is not quite there when it comes to HTML5, we have learned
09:05that based on our skill level, we can either apply CSS to adjust the max width of input,
09:10or we can dive a little deeper in, and modify the Drupal output to enhance the HTML.
09:16Our Drupal theme is pretty much complete, but before we call it a day, I want to take
09:20a look at some responsive tools and techniques that will help you get started earlier in the design process.
Collapse this transcript
10. Responsive Tools and Techniques
Adding min-width and max-width support with Respond.js
00:00Previously, we took a look at adding the CSS property max width to ensure that images,
00:05media, and form elements were responsive.
00:08But what about browsers such as IE6 through IE8 that don't support max width or min width rules?
00:15That's why a handy piece of JavaScript comes in to test which browser is being used and
00:19enables those CSS rules so they display our content correctly.
00:23I introduce you to Respond.js.
00:27You can find this over drupal.org/project/respondjs, and this Drupal module will allow for support
00:34of responsive themes by delivering a lightweight fast support for min width and max width media queries.
00:41Let's go ahead and scroll down to the bottom of the page, click on the zip file to download
00:45it, and once the download is complete, let's go ahead and open up our Downloads folder.
00:50Go ahead and double-click on the file to extract it, and then I want to copy this file over to our
00:55Desktop/Drupal/drupal.responsive/sites/all/modules folder.
01:03Now that we have the module in place, Tab back to over to our Drupal Instance, and then let's log in.
01:09Username and Password is admin all lowercase.
01:11Next, let's navigate our Modules, scroll down to the bottom of the page, and then scroll
01:17a little bit until we find Respond.js.
01:20Go ahead and click on Enabled, save the configuration.
01:25With our module enabled, let's go to our configuration screen.
01:28Scroll down to where we find Respond.js. It will be under the Media section.
01:32There are only two settings we need to worry about. Where we want to Respond.js file be included.
01:38Best practices are to put in this footer. So I choose footer now.
01:42Then I also want to check off Do not warn me about CSS aggregation.
01:46Click on that and then click Save configuration. The configuration options have now been saved.
01:51I'm going to go back to my homepage and then using the Chrome developer tools, Command+Option+I,
01:56I'm going to scroll down to the bottom my code, and down at the bottom I should see the
02:01script being included for Respond.js. It's that simple.
02:06Respond.js to the rescue.
02:08No more concerns over what IE6 through IE8 is not displaying correctly when it comes
02:13to elements that we have targeted with max width CSS rules.
02:18It's very easy to overlook IE, and the Respond.js module makes it simple to integrate into our responsive design workflow.
02:25The last two more techniques that I want to discuss next deals with images and how mobile
02:30devices handle loading them through context aware image sizing.
Collapse this transcript
Exploring context-aware image sizing
00:00One thing we probably don't think about much in the US anymore is bandwidth, and assuming
00:04that everyone must have fast speeds and with more users having mobile devices and 4G speed, why would we?
00:11How about other countries where bandwidth is not so fast?
00:14How does your website look on a mobile device in let's say Africa?
00:18How long does it take to load?
00:20Even though we've applied responsive techniques to our images for them to scale visually,
00:24we are still serving up a larger image file size.
00:28Let's remedy that by discussing context aware image sizing and a technique known as adaptive images.
00:35Let's begin by browsing to drupal.org/projects/adaptive_image.
00:42The adaptive image module provides device- appropriate versions of images from all your fields.
00:48You can activate the adaptive images by simply adding an adaptive effect to any of your image styles.
00:53The technique used is derived from the adaptiveimages.com created by Matt Wilcox.
00:58Let's go ahead and scroll down the page and click on the zip file to download it.
01:02Once the download is complete, go ahead and open up your Downloads folder,
01:06double-click on the file to extract it, and then let's copy this to our
01:11Desktop/Drupal/drupal.responsive/sites/all/modules folder.
01:18With the module in place, go ahead and close the download window, and let's tab back over
01:22to our responsive theme.
01:24Go ahead and log in, Username and Password all lowercase, the word admin, navigate to
01:30modules, and then scroll down the page until we find the module so that we can enable it.
01:34Here we go, Adaptive Image. Make sure it's checked, and then click on Save configuration.
01:40Unlike most modules, though, there is actually no configuration, so to speak.
01:44Instead, we actually need to go to Configuration > Image Styles, and we need to add a new preset for mobile devices.
01:53We can do this by clicking on Add style, giving it a STYLE NAME of mobile, and the naming convention
01:58here is whatever you want to call it, but for my purposes, I'm going to call mobile and
02:03then click on Create new style.
02:05Underneath the Effects, go ahead and select Adaptive and then click Add.
02:08For the resolutions, these are actual breakpoints that we've been dealing with.
02:12For demonstration purposes, I'm going to go ahead and leave the resolutions as is.
02:16But if you have different breakpoints that you're theming against, this is where you
02:20would make those modifications. Notice the Mobile First has been checked.
02:24This will send out to smallest version of the image when the resolution cannot be determined.
02:29Go ahead and click on Add effect.
02:31In order to utilize this effect, we need to go to Structure > Content Types, locate the
02:36content type that you want to use this against.
02:38In our case, the Article which is our blog post that is utilizing images.
02:43I then want to click on manage display, and for the Image field you see a little icon to the right.
02:49If I click on this, I can choose my mobile preset that I just configured.
02:54Go ahead and do that now, click Save, and you're done with the configuration portion.
03:00Go ahead and click on Home, and then let's go ahead and click on Blog, and then go ahead and click
03:05actually on one of the blog posts themselves.
03:08What I'm going to do here is scroll up a little bit, and then I'm actually going to start resizing the page.
03:11And before, everything was fluid.
03:14Now you're actually going to see some different snapping take place.
03:17There is one, there is another, now it scales, and then it jumps back.
03:21So what's happening is it's actually doing an image replacement when you're seeing this
03:25snap based off the different breakpoints.
03:28So we're actually serving up a smaller file size of that image.
03:32Scalable images both visually and physically are now capable depending on where your end
03:37user market is located and the time you want to spend in implementing context aware image sizing.
03:43With the adaptive image module, we're able to achieve that concept very easily and increase the
03:48performance of our design in mobile devices.
03:51The nice thing about this module is we don't have to create different sized images.
03:56By simply making that preset, those images are actually created for us and served up appropriately.
Collapse this transcript
Conclusion
Next steps
00:00I realize we traveled far in a fast amount of time, so you may be asking, where do we go from here?
00:06My recommendation will be taking a look at the remaining lynda.com courses on responsive design.
00:11There are quite a few for you to take a look at and they range from beginner all the way up to advanced.
00:16I'd also say take a look at drupal.org/node/1322126, or in other words, Google Drupal responsive
00:25design, and you'll end up here.
00:27These have some great resources for you on different responsive base themes as well as
00:32it'll get you to started on theming guide when it comes to responsive design.
00:36Also, how about Ethan Marcotte?
00:37Ethan Marcotte is a web designer, developer, and probably one of the most notorious names
00:42in the industry when it comes to responsive design in general.
00:46Then finally, if you want to talk about responsive design when it comes to type, Jason Cranford Teague
00:51has written a lot of great books on Fluid Typography, and you can see his site at jasonspeaking.com.
00:57Finally, last but not least, you want to keep an eye on the Drupal sphere.
01:02Drupal 8 is right around the corner, and it's going to have a lot of responsive goodness baked into it.
01:07Until next time, it's been a pleasure, happy coding.
Collapse this transcript


Suggested courses to watch next:

Responsive Design Fundamentals (2h 15m)
James Williamson

Responsive Design Workflows (1h 20m)
Justin Putney


Drupal 7 Essential Training (7h 23m)
Tom Geller


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,025 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