Professional Documents
Culture Documents
Sass for Responsive Web Design - Marking Content with HTML5 - Mobile-First or Desktop-
First - CSS Grids, CSS Frameworks, UI Kits, and Flexbox for RWD - Designing small UIs by
Large Finger - Images and Videos in Responsive Web Design - Meaningful Typography for
Responsive Web Design
Sass lets you use features that do not exist in CSS, like variables, nested rules, mixins,
imports, inheritance, built-in functions, and other stuff.The basic concepts of Sass for
RWD:
What is Sass?
#a2b9bc
#b2ad7f
#878f99
So, how many times do you need to type those HEX values? A LOT of times. And what about
variations of the same colors?
Instead of typing the above values a lot of times, you can use Sass and write this:
Sass Example
/* define variables for the primary colors */
$primary_1: #a2b9bc;
$primary_2: #b2ad7f;
$primary_3: #878f99;
.menu-left {
background-color: $primary_2;
}
.menu-right {
background-color: $primary_3;
}
So, when using Sass, and the primary color changes, you only need to change it in one place.
A browser does not understand Sass code. Therefore, you will need a Sass pre-processor to
convert Sass code into standard CSS.
This process is called transpiling. So, you need to give a transpiler (some kind of program) some
Sass code and then get some CSS code back.
Tip: Transpiling is a term for taking a source code written in one language and
transform/translate it into another language.
Sass Comments
Sass supports standard CSS comments /* comment */, and in addition it supports inline
comments // comment:
Sass Example
/* define primary colors */
$primary_1: #a2b9bc;
$primary_2: #b2ad7f;
Sass Variables
Variables are a way to store information that you can re-use later.
• strings
• numbers
• colors
• booleans
• lists
• nulls
$variablename: value;
The following example declares 4 variables named myFont, myColor, myFontSize, and
myWidth. After the variables are declared, you can use the variables wherever you want:
mystyle.scss:
body {
font-family: $myFont;
font-size: $myFontSize;
color: $myColor;
}
#container {
width: $myWidth;
}
mystyle.css:
body {
font-family: Helvetica, sans-serif;
font-size: 18px;
color: red;
}
#container {
width: 680px;
border: 1px blue double;
}
mypage.html
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="mystyle.css">
<body>
<h1>Hello World</h1>
<p>This is a paragraph.</p>
</body>
</html>
So, when the Sass file is transpiled, it takes the variables (myFont, myColor, etc.) and outputs
normal CSS with the variable values placed in the CSS, like this:
CSS Output:
body {
font-family: Helvetica, sans-serif;
font-size: 18px;
color: red;
}
#container {
width: 680px;
}
Sass variables are only available at the level of nesting where they are defined.
mystyle.scss:
$myColor: red;
h1 {
$myColor: green;
color: $myColor;
}
p{
color: $myColor;
}
mystyle.css:
h1 {
color: green;
}
p{
color: red;
}
mypage.html:
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="mystyle.css">
<body>
<h1>Hello World</h1>
<p>This is a paragraph.</p>
</body>
</html>
OUTPUT:
The default behavior for variable scope can be overridden by using the !global switch.
!global indicates that a variable is global, which means that it is accessible on all levels.
Look at the following example (same as above; but with !global added):
mystyle.scss:
$myColor: red;
h1 {
$myColor: green !global;
color: $myColor;
}
p{
color: $myColor;
}
mystyle.css:
h1 {
color: green;
}
p{
color: green;
}
mypage.html:
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="mystyle.css">
<body>
<h1>Hello World</h1>
<p>This is a paragraph.</p>
</body>
</html>
OUTPUT:
Now the color of the text inside a <p> tag will be green!
CSS Output:
h1 {
color: green;
}
p{
color: green;
}
Tip: Global variables should be defined outside any rules. It could be wise to define all global
variables in its own file, named "_globals.scss", and include the file with the @include keyword.
Sass lets you nest CSS selectors in the same way as HTML.
mystyle.scss:
nav {
ul {
margin: 0;
padding: 0;
list-style: none;
}
li {
display: inline-block;
}
a{
display: block;
padding: 6px 12px;
text-decoration: none;
}
}
mystyle.css:
nav ul {
margin: 0;
padding: 0;
list-style: none;
}
nav li {
display: inline-block;
}
nav a {
display: block;
padding: 6px 12px;
text-decoration: none;
}
mypage.html:
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="mystyle.css">
<body>
<nav>
<ul>
<li><a href="#">HTML</a></li>
<li><a href="#">CSS</a></li>
<li><a href="#">SASS</a></li>
</ul>
</nav>
</body>
</html>
OUTPUT:
Notice that in Sass, the ul, li, and a selectors are nested inside the nav selector.
While in CSS, the rules are defined one by one (not nested):
CSS Syntax:
nav ul {
margin: 0;
padding: 0;
list-style: none;
}
nav li {
display: inline-block;
}
nav a {
display: block;
padding: 6px 12px;
text-decoration: none;
}
Because you can nest properties in Sass, it is cleaner and easier to read than standard CSS.
Example
SCSS Syntax:
font: {
family: Helvetica, sans-serif;
size: 18px;
weight: bold;
}
text: {
align: center;
transform: lowercase;
overflow: hidden;
}
CSS Output:
text-align: center;
text-transform: lowercase;
text-overflow: hidden;
ass keeps the CSS code DRY (Don't Repeat Yourself). One way to write DRY code is to keep
related code in separate files.
You can create small files with CSS snippets to include in other Sass files. Examples of such
files can be: reset file, variables, colors, fonts, font-sizes, etc.
Sass Importing Files
The @import directive allows you to include the content of one file in another.
The CSS @import directive has a major drawback due to performance issues; it creates an extra
HTTP request each time you call it. However, the Sass @import directive includes the file in the
CSS; so no extra HTTP call is required at runtime!
@import filename;
Tip: You do not need to specify a file extension, Sass automatically assumes that you mean a
.sass or .scss file. You can also import CSS files. The @import directive imports the file and any
variables or mixins defined in the imported file can then be used in the main file.
You can import as many files as you need in the main file:
Example
@import "variables";
@import "colors";
@import "reset";
Let's look at an example: Let's assume we have a reset file called "reset.scss", that looks like this:
Example
html,
body,
ul,
ol {
margin: 0;
padding: 0;
}
and now we want to import the "reset.scss" file into another file called "standard.scss".
Here is how we do it: It is normal to add the @import directive at the top of a file; this way its
content will have a global scope:
@import "reset";
body {
font-family: Helvetica, sans-serif;
font-size: 18px;
color: red;
}
So, when the "standard.css" file is transpiled, the CSS will look like this:
CSS output:
body {
font-family: Helvetica, sans-serif;
font-size: 18px;
color: red;
}
Run Example »
Sass Partials
By default, Sass transpiles all the .scss files directly. However, when you want to import a file,
you do not need the file to be transpiled directly.
Sass has a mechanism for this: If you start the filename with an underscore, Sass will not
transpile it. Files named this way are called partials in Sass.
_filename;
The following example shows a partial Sass file named "_colors.scss". (This file will not be
transpiled directly to "colors.css"):
Example
"_colors.scss":
$myPink: #EE82EE;
$myBlue: #4169E1;
$myGreen: #8FBC8F;
Now, if you import the partial file, omit the underscore. Sass understands that it should import
the file "_colors.scss":
Example
@import "colors";
body {
font-family: Helvetica, sans-serif;
font-size: 18px;
color: $myBlue;
}
The @mixin directive lets you create CSS code that is to be reused throughout the website.
The @include directive is created to let you use (include) the mixin.
Defining a Mixin
@mixin name {
property: value;
property: value;
...
}
SCSS Syntax:
@mixin important-text {
color: red;
font-size: 25px;
font-weight: bold;
border: 1px solid blue;
}
Tip: A tip on hyphens and underscore in Sass: Hyphens and underscores are considered to be the
same. This means that @mixin important-text { } and @mixin important_text { } are considered
as the same mixin!
Using a Mixin
selector {
@include mixin-name;
}
SCSS Syntax:
.danger {
@include important-text;
background-color: green;
}
CSS output:
mystyle.scss:
@mixin important-text {
color: red;
font-size: 25px;
font-weight: bold;
border: 1px solid blue;
}
.danger {
@include important-text;
background-color: green;
}
mystyle.css:
.danger {
color: red;
font-size: 25px;
font-weight: bold;
border: 1px solid blue;
background-color: green;
}
mypage.html:
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="mystyle.css">
<body>
<h1>Hello World</h1>
</body>
</html>
OUTPUT:
SCSS Syntax:
@mixin special-text {
@include important-text;
@include link;
@include special-border;
}
The @extend directive lets you share a set of CSS properties from one selector to another.
The @extend directive is useful if you have almost identically styled elements that only differ in
some small details.
The following Sass example first creates a basic style for buttons (this style will be used for most
buttons). Then, we create one style for a "Report" button and one style for a "Submit" button.
Both "Report" and "Submit" button inherit all the CSS properties from the .button-basic class,
through the @extend directive. In addition, they have their own colors defined:
SCSS Syntax:
.button-basic {
border: none;
padding: 15px 30px;
text-align: center;
font-size: 16px;
cursor: pointer;
}
.button-report {
@extend .button-basic;
background-color: red;
}
.button-submit {
@extend .button-basic;
background-color: green;
color: white;
}
CSS Output:
.button-report {
background-color: red;
}
.button-submit {
background-color: green;
color: white;
}
By using the @extend directive, you do not need to specify several classes for an element in your
HTML code, like this: <button class="button-basic button-report">Report this</button>. You
just need to specify .button-report to get both sets of styles.
The @extend directive helps keep your Sass code very DRY.
URL LINK:
https://www.w3schools.com/sass/sass_functions_map.php
https://www.w3schools.com/css/css_rwd_intro.asp
4. CSS Grids:
What is a grid?
A grid is a set of visual guidelines (vertical, horizontal, or both, hence the term grid)
that help define where elements can be placed. Once the elements have been placed,
we end up with a layout.
CSS grids
A CSS grid is basically a compound of vertical guidelines that form columns. The properties of
these columns are defined in a CSS file. This file contains a list of classes with specific widths
that match the amount of columns that a specific grid is built for.
The pros and cons of CSS grids for RWD:
The advantages are as follows:
• Laying out elements is a lot easier because the columns serve as guidelines
for placement.
• If using a prebuilt CSS grid, there's no need to do any of the math to deal with the column and
gutter widths. It's already taken care of by the author of the grid.
• We can build faster, since all we need to do is add specific classes to our containers in our
HTML and—for the most part—the layout will happen instantly.
• Understanding grids in web design is relatively simple, so enhancing/editing someone else's
markup and code in an already built project is less painful than if they hadn't used a CSS grid at
all.
• If the grid is responsive or adaptive, we don't have to worry too much about
the breakpoints.
• If we are using a third-party CSS grid, any cross-browser issues have already been
addressed.
The disadvantages are as follows:
• Some CSS grids have a steeper learning curve than others.
• With many CSS grids, we are locked into using the name conventions the
author created.
• We may have to change/adapt the way we write our HTML.
• There are so many CSS grids to choose from that it can be overwhelming
for some.
• If our content breaks at certain points the grid doesn't support, we have to spend time
amending the original grid to fit each individual situation.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
display: grid;
grid-template-columns: auto auto auto;
background-color: #2196F3;
padding: 10px;
}
.grid-item {
background-color: rgba(255, 255, 255, 0.8);
border: 1px solid rgba(0, 0, 0, 0.8);
padding: 20px;
font-size: 30px;
text-align: center;
}
</style>
</head>
<body>
<h1>Grid Elements</h1>
<p>A Grid Layout must have a parent element with the <em>display</em> property set to
<em>grid</em> or <em>inline-grid</em>.</p>
<p>Direct child element(s) of the grid container automatically becomes grid items.</p>
<div class="grid-container">
<div class="grid-item">1</div>
<div class="grid-item">2</div>
<div class="grid-item">3</div>
<div class="grid-item">4</div>
<div class="grid-item">5</div>
<div class="grid-item">6</div>
<div class="grid-item">7</div>
<div class="grid-item">8</div>
<div class="grid-item">9</div>
</div>
</body>
</html>
Output:
To make an HTML element behave as a grid container, you have to set the display property
to grid or inline-grid.
Grid containers consist of grid items, placed inside columns and rows.
The grid-template-columns property defines the number of columns in your grid layout, and it
can define the width of each column.
The value is a space-separated-list, where each value defines the width of the respective column.
If you want your grid layout to contain 4 columns, specify the width of the 4 columns, or "auto"
if all columns should have the same width.
<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
display: grid;
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
text-align: center;
padding: 20px 0;
font-size: 30px;
</style>
</head>
<body>
<div class="grid-container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
</div>
</body>
</html>
Output:
The grid-template-columns property can also be used to specify the size (width) of the columns.
<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
display: grid;
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
text-align: center;
padding: 20px 0;
font-size: 30px;
</style>
</head>
<body>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
</div>
</body>
</html>
The align-content property is used to vertically align the whole grid inside the container.
<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
display: grid;
height: 400px;
align-content: center;
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
text-align: center;
padding: 20px 0;
font-size: 30px;
</style>
</head>
<body>
<p>Use the <em>align-content</em> property to vertically align the grid inside the
container.</p>
<p>The value "center" will align the rows in the middle of the container:</p>
<div class="grid-container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
</body>
</html>
You define where the item will start, and where the item will end.
Note: The grid-column property is a shorthand property for the grid-column-start and the grid-
column-end properties.
To place an item, you can refer to line numbers, or use the keyword "span" to define how many
columns the item will span.
Example
<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
display: grid;
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
}
text-align: center;
padding: 20px 0;
font-size: 30px;
.item1 {
grid-column: 1 / 5;
</style>
</head>
<body>
<div class="grid-container">
<div class="item1">1</div>
<div class="item2">2</div>
<div class="item3">3</div>
<div class="item4">4</div>
<div class="item5">5</div>
<div class="item6">6</div>
<div class="item7">7</div>
<div class="item8">8</div>
<div class="item9">9</div>
<div class="item10">10</div>
<div class="item11">11</div>
<div class="item12">12</div>
<div class="item13">13</div>
<div class="item14">14</div>
<div class="item15">15</div>
</div>
</body>
</html>
You define where the item will start, and where the item will end.
The grid-area property can be used as a shorthand property for the grid-row-start, grid-column-
start, grid-row-end and the grid-column-end properties.
The grid-area property can also be used to assign names to grid items.
<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
display: grid;
grid-template-areas:
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
text-align: center;
padding: 20px 0;
font-size: 30px;
</style>
</head>
<body>
<p>You can refer to the name when you set up the grid layout, by using the <em>grid-template-
areas</em> property on the grid container.</p>
<div class="grid-container">
<div class="item1">Header</div>
<div class="item2">Menu</div>
<div class="item3">Main</div>
<div class="item4">Right</div>
<div class="item5">Footer</div>
</div>
</body>
</html>
5. CSS Frameworks:
A CSS framework is a group of prebuilt features that basically help speed up
frontend development for the Web.
6.UI kits:
Similar to CSS frameworks, there is another type of frontend framework called UI
kits. However, UI kits can be a breed of their own.
The following list describes some of the features and characteristics of UI kits:
• There are basically two types of UI kits: those that are built with web technologies (HTML and
CSS) and can be used to prototype web-based applications, and those that are made of (usually)
Photoshop (PSD) files to help mock up and design native mobile apps.
• Very few web-oriented UI kits offer a grid of some sort.
• UI kits are focused on providing user interface components such as sliders, paginations,
navigation bars, dialog boxes, overlays/modals, buttons,typography, tooltips, lists, accordions,
tab systems, carousels/slideshows,forms, and so on.
• In a web-oriented UI kit, the architecture is very modular. This means that each component can
be incorporated into any CSS framework.
UI kits, or user interface kits, help you improve your design workflow. They also encourage
recycling components instead of creating new ones from scratch. They’re commonly used for
mobile design or prototyping, largely because two of the biggest operating systems—iOS and
Android—both have robust, well documented, and heavily supported design systems. (Note that
design systems and UI kits often go hand-in-hand. A design system relates to both the code
components and UI design, while a UI kit refers to the designer’s version of the design system. A
UI kit can stand alone without any relation to a larger design system.
What is a UI kit?
A UI kit is a set of files that contains critical UI components like fonts, layered design files,
icons, documentation, and HTML/CSS files. UI kits can be fairly simple with a few buttons
and design components, or extremely robust with toggles that change fonts, colors, and shapes
on the fly.UI kits save you time and keep you consistent by allowing you to create, edit, or
expand on the existing components without creating them from scratch. Things like
checkboxes, arrows, drop-downs, and forms are not worth re-inventing, especially when
prototyping.
Advantages and disadvantages of UI kits:
UI kits can take time to make, but are worth it in the long run. That being said, they’re not
Advantages
Most notably, UI kits can save you time and money by allowing designers to use their time
more efficiently. When you don’t have to worry about the standard details, you can optimize
your work by focusing on the unique features of the specific site, app, or product you’re
working on. Though it can be an investment to purchase or create a premium UI kit, it’s worth
When everyone knows exactly what size your CTAs should be and what color the cancel
buttons are, your product is more consistent throughout. This allows your users to learn your
also encourages newcomers (to the product or company) to quickly hop on board, giving them
a helpful glimpse into your rules and style preferences. Think of it as the true north for your
UI.
Last but not least, UI kits give you the ability to update styles quickly, easily, and on the fly. If
a client changes the color of their app or site, no big deal. A UI kit allows you to keep
everything organized and categorized so you know that all your CTAs are blue with a 2px
The disadvantages of UI kits are more nuanced, but still worth considering before you dive in.
Depending on the UI kit you create or use, you could be locked into specific components, or be
missing certain ones completely. Not all kits are comprehensive, and if you’re building yours
as you go, you’ll have some gaps. It’s not a huge deal, but it could rob your efficiency instead
of boosting it.
Matching styles from your brand to a different UI kit can be time-consuming. Let’s say you
find a great UI kit that has rounded edges on all the elements, but your client’s brand has
square edges throughout. Smaller components may be easy to change, but matching the style
throughout the entire kit could take a lot of work. If a kit is dramatically different from your
re-learn a new system everytime you switch. Deciphering the layers, naming convention, and
general organization each time can be frustrating, and feel like you’re spending more time on
Examples of UI kits
To help get you started on making your dream project a reality, InVision has a library of high-
Do
With 130 screens and 10 unique themes, this kit provides enough UIs to build all kinds of
Relate
With 45 unique templates, 19 categories, and over 99 UI elements, the Relate UI kit gives you
the resources you need to build immersive mobile app experiences. There’s no optimization
required with vector-only shapes that scale to any size, including retina.
Tethr
This kit provides eight source files, 138 templates, and over 250 UI elements so that you can
Deck
With over 200 UI elements, this cross-platform UI kit is made for designing card-based
interfaces and media websites for desktop, mobile, and tablet formats.
Form
This wireframe kit is like having a head start on your next project, with a huge library of ready-
to-use layouts, components, and symbols. Popular page categories include headers, footers,
pricing tables, blog post templates, feature pages, testimonials, FAQ pages, and more.
You want to design a beautiful user interface but collecting feedback and revising your designs
can be tough if it’s not all in one place. What’s the most efficient way to go about this
important step?
With InVision, it’s easy for your team to share prototypes and quickly gather meaningful
feedback—both in and outside your organization. From early, low-fidelity freehands to high-
fidelity Studio screens, the user feedback is built into the process, empowering your team to
The left and right padding in black are 10px each. We'll convert those 10px into
percentages at the end of this process.
Nested containers:
• Notice that there are several nested containers inside their own row (black background).
The idea here is to highlight the nested content sections that add up to 12 columns.
• Nesting columns are a major advantage of any grid system. In this book, we are
harnessing this power so we don't limit the design in any way.
We're using the HTML5 Shiv polyfill to add HTML5 support to IE8 and below.
On small screens (320px wide), this is what the container looks like:
On large screens starting at 40em (640px) wide, this is what the layout looks like:
You can see the demo I created on CodePen at http://codepen.io/ricardozea/
pen/d6ab6e0293be9b6bac2e16ad37942ed5
Property Description
outline-offset Adds space between an outline and the edge or border of an element
The resize property specifies if (and how) an element should be resizable by the user.
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 2px solid;
padding: 20px;
width: 300px;
resize: horizontal;
overflow: auto;
}
</style>
</head>
<body>
<div>
<p>Let the user resize only the width of this div element.</p>
<p>To resize: Click and drag the bottom right corner of this div element.</p>
</div>
</body>
</html>
The following example lets the user resize only the height of a <div> element:
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 2px solid;
padding: 20px;
width: 300px;
resize: vertical;
overflow: auto;
}
</style>
</head>
<body>
<div>
<p>Let the user resize only the height of this div element.</p>
<p>To resize: Click and drag the bottom right corner of this div element.</p>
</div>
</body>
</html>
The following example lets the user resize both the height and width of a <div> element:
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 2px solid;
padding: 20px;
width: 300px;
resize: both;
overflow: auto;
}
</style>
</head>
<body>
</body>
</html>
In many browsers, <textarea> is resizable by default. Here, we have used the resize property to
disable the resizability:
<!DOCTYPE html>
<html>
<head>
<style>
textarea#test {
resize: none;
}
</style>
</head>
<body>
<p>In many browsers, textarea elements are resizable by default. In this example, we have used
the resize property to disable the resizability:</p>
</body>
</html>
CSS Outline Offset
The outline-offset property adds space between an outline and the edge or border of an element.
Note: Outline differs from borders! Unlike border, the outline is drawn outside the element's
border, and may overlap other content. Also, the outline is NOT a part of the element's
dimensions; the element's total width and height is not affected by the width of the outline.
The following example uses the outline-offset property to add space between the border and the
outline:
<!DOCTYPE html>
<html>
<head>
<style>
div.ex1 {
margin: 20px;
outline-offset: 15px;
div.ex2 {
margin: 10px;
outline-offset: 5px;
</style>
</head>
<body>
<div class="ex1">This div has a 4 pixels solid red outline 15 pixels outside the border
edge.</div>
<br>
<div class="ex2">This div has a 5 pixels dashed blue outline 5 pixels outside the border
edge.</div>
</body>
</html>
url link:
https://www.w3schools.com/css/css3_user_interface.asp
Flexbox Elements
To start using the Flexbox model, you need to first define a flex container.
he element above represents a flex container (the blue area) with three flex items.
Example
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
background-color: DodgerBlue;
background-color: #f1f1f1;
margin: 10px;
padding: 20px;
font-size: 30px;
</style>
</head>
<body>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
<p>A Flexible Layout must have a parent element with the <em>display</em> property set
to <em>flex</em>.</p>
</body>
</html>
The flex container becomes flexible by setting the display property to flex:
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
background-color: DodgerBlue;
background-color: #f1f1f1;
margin: 10px;
padding: 20px;
font-size: 30px;
</style>
</head>
<body>
<h1>Create a Flex Container</h1>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
<p>A Flexible Layout must have a parent element with the <em>display</em> property set
to <em>flex</em>.</p>
</body>
</html>
The following table lists all the CSS Flexbox Container properties:
Property Description
align-content - Modifies the behavior of the flex-wrap property. It is similar to align-items, but
instead of aligning flex items, it aligns flex lines
align-items - Vertically aligns the flex items when the items do not use all available space on
the cross-axis
flex-direction - Specifies the direction of the flexible items inside a flex container
flex-wrap Specifies whether the flex items should wrap or not, if there is not enough room
for them on one flex line
justify-content Horizontally aligns the flex items when the items do not use all available space
on the main-axis
The flex-direction property defines in which direction the container wants to stack the flex items.
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
flex-direction: column;
background-color: DodgerBlue;
background-color: #f1f1f1;
width: 100px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
</style>
</head>
<body>
<p>The "flex-direction: column;" stacks the flex items vertically (from top to bottom):</p>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</body>
</html>
Example
The column-reverse value stacks the flex items vertically (but from bottom to top):
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
flex-direction: column-reverse;
background-color: DodgerBlue;
background-color: #f1f1f1;
width: 100px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
</style>
</head>
<body>
<p>The "flex-direction: column-reverse;" stacks the flex items vertically (but from bottom
to top):</p>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</body>
</html>
Example
The row value stacks the flex items horizontally (from left to right):
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
flex-direction: row;
background-color: DodgerBlue;
background-color: #f1f1f1;
width: 100px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
</style>
</head>
<body>
<p>The "flex-direction: row;" stacks the flex items horizontally (from left to right):</p>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</body>
</html>
Example
The row-reverse value stacks the flex items horizontally (but from right to left):
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
flex-direction: row-reverse;
background-color: DodgerBlue;
background-color: #f1f1f1;
width: 100px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
</style>
</head>
<body>
<p>The "flex-direction: row-reverse;" stacks the flex items horizontally (but from right to
left):</p>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</body>
</html>
The flex-wrap property specifies whether the flex items should wrap or not.
The examples below have 12 flex items, to better demonstrate the flex-wrap property.
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
flex-wrap: wrap;
background-color: DodgerBlue;
}
background-color: #f1f1f1;
width: 100px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
</style>
</head>
<body>
<p>The "flex-wrap: wrap;" specifies that the flex items will wrap if necessary:</p>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
</div>
</body>
</html>
Example
The wrap value specifies that the flex items will wrap if necessary:
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
flex-wrap: wrap;
background-color: DodgerBlue;
background-color: #f1f1f1;
width: 100px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
</style>
</head>
<body>
<p>The "flex-wrap: wrap;" specifies that the flex items will wrap if necessary:</p>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
</div>
</body>
</html>
Example
The nowrap value specifies that the flex items will not wrap (this is default):
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
flex-wrap: nowrap;
background-color: DodgerBlue;
.flex-container>div {
background-color: #f1f1f1;
width: 100px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
</style>
</head>
<body>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
</div>
</body>
</html>
Example
The wrap-reverse value specifies that the flexible items will wrap if necessary, in reverse order:
.flex-container {
display: flex;
flex-wrap: wrap-reverse;
}
The flex-flow property is a shorthand property for setting both the flex-direction and flex-
wrap properties.
Example
.flex-container {
display: flex;
flex-flow: row wrap;
}
The justify-content Property
Example
The center value aligns the flex items at the center of the container:
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
justify-content: center;
background-color: DodgerBlue;
background-color: #f1f1f1;
width: 100px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
</style>
</head>
<body>
<p>The "justify-content: center;" aligns the flex items at the center of the container:</p>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</body>
</html>
Example
The flex-start value aligns the flex items at the beginning of the container (this is default):
.flex-container {
display: flex;
justify-content: flex-start;
}
Example
The flex-end value aligns the flex items at the end of the container:
.flex-container {
display: flex;
justify-content: flex-end;
}
Example
The space-around value displays the flex items with space before, between, and after the lines:
.flex-container {
display: flex;
justify-content: space-around;
}
Example
The space-between value displays the flex items with space between the lines:
.flex-container {
display: flex;
justify-content: space-between;
}
URL link:
https://www.w3schools.com/css/css3_flexbox_container.asp
8. Designing small UIs by Large Finger:
The intense popularity of touchscreen devices is nothing new to us—the web/mobile designers
and developers. So we're not going to talk about market shares, statistics, or analytics numbers.
Instead, we're going to talk about the things we need to consider to build a usable interface, such
as target sizes, navigation patterns, navigation icons, best practices and mobile device
ergonomics.
The ideal target sizes on small UIs All vendors have different sets of rules and guidelines
regarding the ideal size of targets on small screen devices. Some of them refer to these sizes in
pixels, others in points, and others in units such as inches, millimeters, or centimeters.
Regardless of the units these vendors use, they all agree on one basic concept: make your target
size big enough to avoid accidental taps. This goes in hand with Fitts's law, which states that the
smaller the target, the longer the user will take to reach it.
Obviously, as web designers, we have to be mindful of what large means in the context of our
designs, so we need to balance the target size recommendations with good design principles. Our
aim is that the messages should reach the users and they should be able to comfortably use our
interfaces
One thing to keep in mind is that the guidelines for target sizes for RWD are mostly based on
mobile apps design patterns. Let's get right to it. The average width of an adult's index finger is
about 16 mm to 20 mm. This is close to 45px to 57px. According to Apple's iOS Human
Interface Guidelines, the recommended minimum target size is 44pt x 44pt
Note: The reason some user interface guidelines use points and millimeters as their measuring
units is to provide a consistent scale that is device independent. That's because 1px in one device
may not necessarily mean exactly 1px in another device. Nonetheless, some vendors do provide
guidelines on pixels, but mostly so we can get an idea of how an element's proportions relate to
one another.
The Android Developers guidelines recommend a minimum target size of 48dp, which is about 9
mm. The minimum and maximum recommended target sizes are 7 mm and 10 mm, respectively.
The Android Developers guidelines also recommend a minimum spacing between elements of
8dp.
Note: Here, dp means density-independent pixels. This means that 1dp is the same as 1px in
normal density screens. Just like Apple with the use of points (pt), they are trying to define a unit
that is global and screen density independent.
The posture patterns and the touch zones
No matter how usable the sizes of our touch targets are, if they are not placed in the right
location, all our efforts are pretty much worthless.
The posture patterns:
In his article, Luke talks about the patterns of posture most users have when holding their
smartphones, tablets, and touch-enabled laptops:
These patterns allow us to define the best way to lay out our content in order to be easily usable
and accessible. Understanding the posture patterns of our users will allow us to understand when
our targets can be the right size or even a bit smaller if there isn't enough screen real estate, or a
bit larger if precision is needed, since it's different when someone uses their thumbs as opposed
to their index fingers.
The touch zones:
Luke also talks about touch zones, which are basically the areas of a device that are either easy
or hard to reach, depending on the posture. In all major styles of devices, smartphones, tablets
and touch-enabled laptops, the ideal touch zones are in dark green, the ok touch zones are in
lighter green, and the hard-to-reach zones are in yellow:
In RWD, it's a bit hard to drastically change the layout of a single page, let alone many pages (at
least yet) like a standalone app, without an exorbitant amount of work. Also, there is a very high
probability of negatively impacting the user experience and maintaining the content hierarchy.
RWD is strongly coupled with content strategy, so the content hierarchy needs to be preserved
regardless of the device our site/app is being viewed on. We need to make sure the elements
themselves are big enough for someone with large fingers to use properly. These elements are, to
name a few, links, buttons, form fields, navigation items, controls of any sort like paginations,
open/collapse controls in accordions, tab systems, and so on.
The nav icon – basic guidelines to consider for RWD:
The nav icon can be represented in many ways. RWD takes patterns from mobile apps since
small screens apps and websites have many similar metaphors. Let's take a look at the common
navigation icon patterns:
• The hamburger icon.
• The word Menu.
• The hamburger icon plus the word Menu
The hamburger icon:
This is by far the most popular icon used to represent the navigation button: ≡.
The advantages are as follows:
• It's easily recognized by certain demographics, especially young ones.
• It takes up very little space in a design.
• It's not language dependent.
• It's easy to make using the Unicode character 2261 (≡), which has a global support of 96
percent.
The disadvantages are as follows:
• It's not easily recognized by some demographics, especially older ones.
• Although very popular, a lot of people have a hard time understanding that the hamburger icon
represents a menu.
• It promotes low discoverability since a site's navigation will usually be hidden.
The word Menu:
Some informal tests on the web have yielded that using the word Menu is the most trusted
solution to the drawbacks of the hamburger icon.
The advantages are as follows:
• It's self-explanatory.
• Virtually anyone from any demographic can understand what it means.
• It can be used in any language.
• It takes up very little space in the design
The disadvantage is as follows:
• It may clash with an iconography system since it's a word.
Consider the following example.
Here's the HTML:
One alternative to the hamburger icon versus the word Menu discussion is to use both at the
same time. Some argue that we may get the best of both worlds by doing this.
• It's self-explanatory.
• It is easy to make using the Unicode character 2261 (≡), which has a global support of 96
percent.
One of the most mystifying features of RWD is the navigation. It can be as simple or as complex
as we want it to be.
In this section, I'm going to show you how to build three commonly used navigation patterns:
• Off-Canvas or Off-Screen navigation: This is based on Austin Wulf's SitePoint Pure CSS
Off-Screen Navigation Menu demo (http://codepen.io/ SitePoint/pen/uIemr/).
The only reason we would need to use a polyfill is to support those browsers (legacy and
modern) that haven't yet implemented support for them.
Both the element and the srcset attribute have a fallback feature for those browsers that don't
support them. You can opt to use a polyfill, but you are not required to do so. If you think using a
polyfill enhances the user experience, by all means, go for it. Read this article about it from the
creator of the Picturefill polyfill, Scott Jehl (http:// www.filamentgroup.com/lab/to-
picturefill.html).
There are many polyfills out there, here's a short list of the ones we can use today:
Some people in the web design and web development communities feel strongly about
considering that a new HTML element () isn't the solution to the issues we are experiencing with
images in RWD. They feel that the solution should come from within an already existing tag, the
<img> tag.
Note: 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. Good for us, that the solutions come in both
flavors. It doesn't matter which method you use to serve your images in a responsible way, what
matters is that you should be using one of these methods. If you already are, that's awesome. If
not, don't sweat it. The following explanations will help clear up any questions you have about
this matter.
If the width property is set to a percentage and the height property is set to "auto", the image will
be responsive and scale up and down:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
img {
width: 100%;
height: auto;
</style>
</head>
<body>
<p>Resize the browser window to see how the image will scale.</p>
</body>
</html>
Output:
Example
img {
max-width: 100%;
height: auto;
}
If the width property is set to 100%, the video player will be responsive and scale up and down:
<!DOCTYPE html>
<html>
<head>
<style>
video {
width: 100%;
height: auto;
</style>
</head>
<body>
<p>Resize the browser window to see how the size of the video player will scale.</p>
</body>
</html>
If the max-width property is set to 100%, the video player will scale down if it has to, but never
scale up to be larger than its original size:
Example
video {
max-width: 100%;
height: auto;
}
Typography is the art and technique of arranging type. It involves the thoughtful and
deliberate selection of typefaces, point size, line length, leading, tracking, kerning, color and any
element that can affect a design.
Pixels, ems, or rems for typography?
It is difficult to decide whether to use pixels, ems, or rems for typography. It's a matter of style.
Some web designers/developers still use pixels as their unit to declare font sizes. It's just a lot
easier to wrap our heads around the sizes.
There's also another similar magic formula to calculate relative font sizes (ems) when the font
size has been set in pixels. The only difference is that we don't multiply by 100.
The Modular Scale was created by Tim Brown. There are different ways to create a Modular
Scale for typography. In our example, we're going to create a Modular Scale using two base
numbers and one ratio. The multiplication of these numbers creates a scale that's harmonious and
proportional between all the values.
Once the web app opens, there are three steps we need to do in order to create our Modular
Scale:
3. Choose a ratio.
The recommended way to define this first number is to use the body text size, that is, the font
size that is used in the paragraphs. But keep in mind that using the body text size as the first base
number is not mandatory. We can use our typeface's x-height, or some other length within that
typeface, that we think could be a good starting point.
Although we can choose any font size, let's start with the default one we all know all browsers
use, 16px. So we type 16px in the first base field.
When I say tightly related I mean something like using the width of the main container, for
example, 960px, 980px, 1140px, and so on. Alternatively, it can also be the number of columns
used in the grid, such as 12 or 16. It can also be the width of a column at the maximum width of
the site, such as 60px, or even the gutter spacing, say 20px.
This magic number is anything we want it to be, but it's directly related to our project in one way
or another. For this example, let's say we're going to target screens at a maximum width of
1280px, so our main container is going to have a maximum width of 1140px. So let's type
1140px in the second base field.
Choosing a ratio:
This is where the magic takes place. Choosing a ratio means that this ratio will be multiplied by
the base numbers creating a scale of values that are proportionally related.
The ratios are based on musical scales, and in that list is the golden ratio (1.618) as well, if we
decide to use it. From the Ratios dropdown, select 1:1.618 – golden section ratio.
The font sizes provided by this Modular Scale are totally harmonious because they are
proportionate to each other based on relevant values that are directly related to our project:
If you click on the Table view, all the text is now gone and we're left with a list of font sizes—
ranging from ridiculously small values to just as ridiculously large values. But that's ok. That's
the power of a modular scale.
As you can see in the preceding image, there are three columns:
• The third column shows the font size if the base was 16px.
The rems-to-pixels Sass mixin:
All we need is a Sass mixin that allows us to set the font values without a specific unit
and the mixin takes care of adding the font sizes for both rem-based for modern browsers, and
the pixel-based for legacy browsers.
This is the Sass mixin created by Chris Coyer:
Web fonts are almost mandatory to use nowadays, and I say almost because we need to be
mindful of the implications they bring to our projects, and if necessary, we may actually not use
them at all. Before we get into the nitty gritty of how to work with web fonts, here are a few web
font resources that may be helpful for many of you:
• Font Squirrel
• Google Fonts
• Adobe Edge Web Fonts
• They help accentuate the brand and create consistency across different media.
• This keeps the text as HTML making the content more accessible and indexable.
• They slow down the website/app due to HTTP requests or their dependency on third-party
servers.
• Not all web fonts are legible at small and/or large sizes.
• If legacy browsers are required to support, there are more files to manage.
• Licensing the use of a font requires some sort of payment: monthly, per font family, per font
style, and so on.
° Flash Of Unstyled Text (FOUT): On modern browsers, when the page loads, the text is first
rendered on the screen with a system font, and then a second later it's swapped and styled with
the web font.
° Flash Of Invisible Text (FOIT): On legacy browsers, when the page loads, the text is not
visible but a second later it's rendered with the web font.
Defining thresholds :
There's a potential problem with the solution we just saw: FlowType.js will modify the font size
of the paragraphs indefinitely. In other words, on small screens the text will be extremely small
and on large screens it will be way too big.
We can solve this issue with two separate threshold approaches or a combination of both.
Now, one thing we need to make clear is that this part will require some tweaking and adjusting
in order to get the best results, there aren't specific values that will work for all situations.
• Define the minimum and maximum font sizes of the container or element.
Threshold widths:
Defining the minimum and maximum widths will tell FlowType.js at which points it should stop
resizing. Let's define the width thresholds:
$(function() {
$("html").flowtype( {
maximum: 980,
minimum: 320
});
});
Just like with the width thresholds, defining the minimum and maximum font sizes will tell
FlowType.js what the smallest and largest font sizes it should scale the text to.
We're also going to declare our own font size using the fontRatio variable; the higher the
number, the smaller the font, and the lower the number, the larger the font. If this feels
counterintuitive, look at it this way: the higher the number, the higher the compression (thus
making it small) and the lower the number, the lower the compression (thus making it large).
Adjusting the fontRatio value is an eyeballing exercise, so tweak and test like there's no
tomorrow.