Monday, December 3, 2018

CSS: responsive design Intro

Viewport:  is the user's visible area of a web page.

HTML5 introduced a method to let web designers take control over the viewport, through the tag.
You should include the following viewport element in all your web pages:





A viewport element gives the browser instructions on how to control the page's dimensions and scaling.

The width=device-width part sets the width of the page to follow the screen-width of the device (which will vary depending on the device).

The initial-scale=1.0 part sets the initial zoom level when the page is first loaded by the browser.

Some notes on fitting the content to the viewport


1. Do NOT use large fixed width elements - For example, if an image is displayed at a width wider than the viewport it can cause the viewport to scroll horizontally. Remember to adjust this content to fit within the width of the viewport.

2. Do NOT let the content rely on a particular viewport width to render well - Since screen dimensions and width in CSS pixels vary widely between devices, content should not rely on a particular viewport width to render well.

3. Use CSS media queries to apply different styling for small and large screens - Setting large absolute CSS widths for page elements will cause the element to be too wide for the viewport on a smaller device. Instead, consider using relative width values, such as width: 100%. Also, be careful of using large absolute positioning values. It may cause the element to fall outside the viewport on small devices.

Grid System

A responsive grid-view often has 12 columns, and has a total width of 100%, and will shrink and expand as you resize the browser window

CSS Media Query

It uses the @media rule to include a block of CSS properties only if a certain condition is true

@media only screen and (max-width : 100px) {

Body {
   Background-Colour : #009922
}

}

Design Mobile first
Mobile First means designing for mobile before designing for desktop or any other device (This will make the page display faster on smaller devices).

For e.g. Instead of changing styles when the width gets smaller than 768px, we should change the design when the width gets larger than 768px. This will make our design Mobile First:


References:
https://www.w3schools.com/css/css_rwd_intro.asp

No comments:

Post a Comment