Responsive Web Design

What is Responsive Web Design?

Responsive web design makes your web page look good on all devices.

Responsive web design uses only HTML and CSS.

Responsive web design is not a program or a JavaScript.

Designing For The Best Experience For All Users

Web pages can be viewed using many different devices: desktops, tablets, and phones. Your web page should look good, and be easy to use, regardless of the device.

Web pages should not leave out information to fit smaller devices, but rather adapt its content to fit any device: Continue reading Responsive Web Design

CSS Grid Item

Grid Items

A grid container contains one or more grid items.

By default, a container has one grid item for each column, in each row, but you can style the grid items so that they will span multiple columns and/or rows.

The grid-column-start and grid-column-end Properties

The grid-column-start property specifies where to start a grid item.

The grid-column-end property specifies where to end a grid item.

Example

Place the first grid item at column-line 1, and let it end on column-line 3:

.item1 {
  grid-column-start: 1;
  grid-column-end: 3;
}

Continue reading CSS Grid Item

CSS Grid Container

Grid Container

A grid container contains one or more grid items arranged in columns and rows.

Direct child elements(s) of the grid container automatically becomes grid items.

An element becomes a grid container when its display property is set to grid or inline-grid.

Grid Tracks

The rows and columns of a grid is defined with the grid-template-rows and the grid-template-columns properties (or the shorthand grid or grid-template properties).

These define the grid tracks. A grid track is the space between two adjacent grid lines. Continue reading CSS Grid Container

CSS Grid Columns, Rows and Gaps

Grid Columns

The vertical lines of grid items are called columns.

Grid Rows

The horizontal lines of grid items are called rows.

Grid Gaps

The spaces between each column/row are called gaps.

Continue reading CSS Grid Columns, Rows and Gaps

CSS Grid Layout Module

See the Pen
CSS Grid Layout Module
by Iampsp.com (@iampsp)
on CodePen.

Continue reading CSS Grid Layout Module

CSS Responsive Flexbox

Responsive Flexbox

You learned from the CSS Media Queries chapter that you can use media queries to create different layouts for different screen sizes and devices.

For example, if you want to create a two-column layout for most screen sizes, and a one-column layout for small screen sizes (such as phones and tablets), you can change the flex-direction from row to column at a specific breakpoint (800px in the example below):

Example

.flex-container { display: flex; flex-direction: row; }/* Responsive layout - makes a one column layout instead of a two-column layout */ @media (max-width: 800px) { .flex-container { flex-direction: column; } }

Continue reading CSS Responsive Flexbox

CSS Flex Items

The CSS Flex Items

The direct child elements of a flex container automatically becomes flex items.

The element above represents four blue flex items inside a grey flex container.

Example

<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>

Continue reading CSS Flex Items

CSS Flex Container

The CSS Flex Container

The flex container becomes flexible by setting the display property to flex:

Example

.flex-container {
  display: flex;
}

Continue reading CSS Flex Container

CSS Flexbox

See the Pen
CSS Flexbox
by Iampsp.com (@iampsp)
on CodePen.

What is CSS Flexbox?

Flexbox is short for the Flexible Box Layout module.

Flexbox is a layout method for arranging items in rows or columns.

Flexbox makes it easier to design a flexible responsive layout structure, without using float or positioning.

Flexbox vs. Grid

The CSS Flexbox Layout should be used for one-dimensional layout, with rows OR columns.

The CSS Grid Layout should be used for two-dimensional layout, with rows AND columns.

Continue reading CSS Flexbox

CSS Media Queries

CSS Media Queries

The @media rule, introduced in CSS2, made it possible to define different style rules for different media types.

Media queries in CSS3 extended the CSS2 media types idea: Instead of looking for a type of device, they look at the capability of the device.

Media queries can be used to check many things, such as:

  • width and height of the viewport
  • orientation of the viewport (landscape or portrait)
  • resolution

Using media queries are a popular technique for delivering a tailored style sheet to desktops, laptops, tablets, and mobile phones (such as iPhone and Android phones).


CSS Media Types

Value Description
all Used for all media type devices
print Used for print preview mode
screen Used for computer screens, tablets, smart-phones etc.

CSS Common Media Features

Here are some commonly used media features:

Value Description
orientation Orientation of the viewport. Landscape or portrait
max-height Maximum height of the viewport
min-height Minimum height of the viewport
height Height of the viewport (including scrollbar)
max-width Maximum width of the viewport
min-width Minimum width of the viewport
width Width of the viewport (including scrollbar)

Media Query Syntax

A media query consists of a media type and can contain one or more media features, which resolve to either true or false.

@media not|only mediatype and (media feature) and (media feature) {
CSS-Code;
}

The mediatype is optional (if omitted, it will be set to all). However, if you use not or only, you must also specify a mediatype.

The result of the query is true if the specified media type matches the type of device the document is being displayed on and all media features in the media query are true. When a media query is true, the corresponding style sheet or style rules are applied, following the normal cascading rules.

Meaning of the not, only, and and keywords:

not: This keyword inverts the meaning of an entire media query.

only: This keyword prevents older browsers that do not support media queries from applying the specified styles. It has no effect on modern browsers.

and: This keyword combines a media type and one or more media features.

You can also link to different stylesheets for different media and different widths of the browser window (viewport):

<link rel="stylesheet" media="print" href="print.css">
<link rel="stylesheet" media="screen" href="screen.css">
<link rel="stylesheet" media="screen and (min-width: 480px)" href="example1.css">
<link rel="stylesheet" media="screen and (min-width: 701px) and (max-width: 900px)" href="example2.css">
etc....

Continue reading CSS Media Queries