Book Image

Mastering Responsive Web Design

By : Ricardo Zea
Book Image

Mastering Responsive Web Design

By: Ricardo Zea

Overview of this book

Building powerful and accessible websites and apps using HTML5 and CSS3 is a must if we want to create memorable experiences for our users. In the ever-changing world of web design and development, being proficient in responsive web design is no longer an option: it is mandatory. Each chapter will take you one step closer to becoming an expert in RWD. Right from the start your skills will be pushed as we introduce you to the power of Sass, the CSS preprocessor, to increase the speed of writing repetitive CSS tasks. We’ll then use simple but meaningful HTML examples, and add ARIA roles to increase accessibility. We’ll also cover when desktop-first or mobile-first approaches are ideal, and strategies to implement a mobile-first approach in your HTML builds. After this we will learn how to use an easily scalable CSS grid or, if you prefer, how to use Flexbox instead. We also cover how to implement images and video in both responsive and responsible ways. Finally, we build a solid and elegant typographic scale, and make sure your messages and communications display correctly with responsive emails.
Table of Contents (16 chapters)
Mastering Responsive Web Design
Credits
About the Author
Acknowledgment
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Before the days of Responsive Web Design, web designers' and frontend developers' efforts were pretty much focused on translating print layouts into websites and applications. Elements and dimensions were rigid, and the need for them to adapt and scale wasn't part of the concepts we mandatorily have to account for today.

Devices come in many shapes and sizes. All sorts of screen densities, aiming our work for operating systems and browsers that support (or don't support) certain HTML, CSS and JavaScript technologies, UX principles, usability best practices, and knowing how mobile devices affect the world we live in are now an "intricate" part of what we do as web designers and frontend developers.

In this book, I provide a lot of information, technical and conceptual, about how RWD provides a pathway to better websites and web apps. Installing and using Sass, handling images and videos, and creating a solid typographic scale to building responsive e-mails are a few of the content gems you'll be able to read in this book.

Time to level up!

What this book covers

Chapter 1, Harness the Power of Sass for Responsive Web Design, starts with the easiest walkthrough you'll ever read on how to install Sass; then we learn how to make Sass "watch" our SCSS files. Then, there are easy-to-understand explanations about basic Sass concepts such as variables, mixins, arguments, nesting, partial files, the @import directive, source maps, and Sass comments. We also learn to automate vendor prefixing and automatically compile our SCSS files with Prepros. We talk about creating mixins to address media queries as easily as possible, considering how content defines the breakpoints.

Chapter 2, Marking Our Content with HTML5, clarifies that HTML is a markup language, not code. Then, we talk about the most used HTML5 elements that allow us to markup our content semantically. Improving the accessibility of our builds with ARIA roles is also something we address in a simple way. We also talk about the different meta tags required for RWD, and then we have an example that brings everything together.

Chapter 3, Mobile-first or Desktop-first?, demystifies why and when mobile-first or desktop-first should be used. With examples, we will learn how to retrofit a site with Adaptive Web Design, and of course, with RWD. We will learn about Respond.js and conditional classes in order to support legacy browsers when building mobile-first.

Chapter 4, CSS Grids, CSS Frameworks, UI Kits, and Flexbox for RWD, helps us understand what a grid is, how to use it, and why. With this understanding, we can make sound decisions when building a website or web app. We also create a custom CSS grid both with the floats technique and then by using Flexbox. We will use conditional classes again to address old browsers, and with the help of a small script, we can take care of the quirks from IE10 with an .ie10 specific selector.

Chapter 5, Designing Small UIs Driven by Large Finger, shows how usability and accessibility play a major role in this chapter. We also find explanations about the different sizes of our target zones, the location of our controls (links, buttons, form fields, and so on), and the touch zones in different devices. There are also three examples on how to create a menu button plus three more examples on mobile navigation patterns.

Chapter 6, Working with Images and Videos in Responsive Web Design, is one of the most interesting chapters of this book because images in RWD are a "thing". We will talk about different ways to serve different images with the <picture> element and the srcset attribute. Making videos responsive with CSS, jQuery, and JavaScript is also addressed in this chapter. We also learn about using vector-based files such as icon fonts and SVGs.

Chapter 7, Meaningful Typography for Responsive Web Design, talks about using relative units being ideal because they provide scalability, and this is what RWD is all about. The golden egg in this chapter is that we will learn how to use the Modular Scale to create a harmonious typographic scale. We will also use Flowtype.js to increase the legibility of our copy.

Chapter 8, Responsive E-mails, shows that e-mails are opened more on mobile devices than on desktops; that responsive e-mails have more engagement on mobile devices than nonresponsive ones; and that people click on e-mails on desktops more than on mobile. We will also create an e-mail template as an example. We'll learn to use a CSS reset block to normalize those quirky e-mail clients and learn that the best width for e-mails is not more than 600 pixels.

All these chapters have CodePen demos.

What you need for this book

There are a few considerations to follow the examples in this book: a text editor or IDE (Sublime Text is used in this book), Internet access, and admin rights to your machine to install applications.

You may also need an image editing software such as Photoshop, Fireworks, or GIMP. If you use something else, that's totally fine.

If possible, you can use one or two types of real mobile devices in order to experience the examples and demos in the right context. Otherwise, using Chrome's DevTool's Device Mode feature would work as well.

Who this book is for

If you already know some HTML and CSS and understand the principles of Responsive Web Design, this book is for you. There's something here for you to learn regardless of whether you're a web designer or web developer, or whether you're a beginner or a seasoned web professional.

A good understanding of HTML and CSS is required since RWD relies heavily on these technologies. Some understanding of jQuery is also recommended, but not mandatory.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The sizes attribute can also be used with the <picture> element, but we're going to focus on using the sizes attribute with the <img> tag."

A block of code is set as follows:

*, *:before, *:after {
    box-sizing: border-box;
}

//Moble-first Media Queries Mixin
@mixin forLargeScreens($width) {
    @media (min-width: $width/16+em) { @content }
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

*, *:before, *:after {
    box-sizing: border-box;
}

//Moble-first Media Queries Mixin
@mixin forLargeScreens($width) {
    @media (min-width: $width/16+em) { @content }
}

Any command-line input or output is written as follows:

gem install sass

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "clicking the Next button moves you to the next screen".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

If you have any questions, don't hesitate to look me up on Twitter via @ricardozea, I will be more than glad to help a fellow web professional wherever, whenever.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/2102_0234_ImageBundle.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.