Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • HTML5 Responsive Design - ViewPort Meta Tag (Part 3)

    • 0
    • 2
    • 3
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.58k
    Comment on it

    Hi again,

    In this article, were going to focus on another important concept of responsive design, i.e. the 'Viewport Meta Tag'.

    View-Port Overview

    The viewport meta tag was introduced by Apple to help web developers improve the way web pages are displayed on the iPhone but obviously now its used for all mobile devices. This basically tells a mobile device, that the current page is optimized for mobile and it should display it in a certain way and not in the default web layout. In simple words: A meta viewport tag provides the instructions to the browser on how to manage the page's dimensions and scaling. The zooming in and out of the page that you can do is because of this whole viewport business only. Lets look at how we use the meta tag:

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    In the above example, this meta tag instructs the mobile device to not zoom. This allows the responsive design for mobile devices to be loaded in the scripts.

    Meta tag "data"property attributes for "viewport"

    Virtual Viewport can be split into two:
    1. Visual Viewport: The part of the page which is currently shown on the screen.

    2. Layout Viewport: Visual Viewport + The part of the page which currently lies outside the display area. This is basically the mobile equivalent of desktop resolution. Safari iPhone uses 980px, Opera 850px, Android WebKit 800px, and IE 974px as the default.

    In the above examples, we saw only two properties of the viewport meta tag: width and initial-scale; but there are others which are listed in the following table:

    Property

    Description

    width

    The width of the virtual viewport of the device.

    device-width

    The physical width of the device's screen.

    height

    The height of the "virtual viewport" of the device.

    device-height

    The physical height of the device's screen.

    initial-scale

    The initial zoom when visiting the page. 1.0 does not zoom.

    minimum-scale

    The minimum amount the visitor can zoom on the page. 1.0 does not zoom.

    maximum-scale

    The maximum amount the visitor can zoom on the page. 1.0 does not zoom.

    user-scalable

    Allows the device to zoom in and out. Values are yes or no.

    Above mentioned properties of the viewport would be added in the 'Head' section of our website. Below are some examples which show how we can implement these viewport elements:

    • In case your mobile design is set at 320px, we can specify the viewport width:
    • <meta name="viewport" content="width=320">

    • For fluid layouts, we need to match our layout width to the device width:
    • <meta name="viewport" content="width=device-width">

    • To take the advantage of the entire landscape mode and to manage full screen mode of device browser, we add the attribute 'initial-scale=1', which command the device browsers to form a 1:1 relationship between CSS Pixels and the Device Independent Pixels (DIPs) irrespective of device orientation:
    • <meta name="viewport" content="initial-scale=1">

    • Arrange an accessible viewport: In addition to set the initial-scale, we can also control the following attributes on the viewport:
      1. minimum-scale

      2. maximum-scale

      3. user-scalable

      These attributes are essential to restrict the user's ability to zoom the viewport, potentially creating content render issues.

    • Combining Viewport Values: The viewport meta tag can add individual values as well as multiple values, allowing multiple viewport properties to be set at once.

      ** Whenever we need to add or combine multiple viewport attributes in a single set, we have to use Comma(,) after the attribute. E.g.:

      <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    CSS Viewport Rule:

    This specification provides a way for an author to specify, in CSS, the size, zoom factor, and orientation of the viewport that is used as the base for the initial containing block.

    - w3.org

    Basically, this rule allows one to attain the functionality of the viewport meta tag by way of CSS @viewport keyword without cluttering up their HTML. This method helps to keep the style separately for content and provide a more semantic approach. Like viewport meta tag was introduced by Apple, this approach was first proposed by Microsoft in the light of IE10 explorer ignoring viewport meta tag in some situations.

    Examples

    @viewport {

    width: device-width;

    zoom: 1;

    }

    @-ms-viewport{

    width: extend-to-zoom;

    zoom: 1.0;

    }

    End of this Session

    In my last two blogs, I talked about the 'Media Queries' for responsive design. These are as follows:

    1. HTML5 Responsive Design- media Queries Tutorial 01
    2. HTML5 Responsive Design- media Queries Tutorial 02

    In this session, I have tried to cover as many aspects of 'ViewPort' as to give the reader a good enough understanding of its role in responsive design. However, the field of responsive design in itself is quite broad, so Ill be coming up with some new related topics in my next articles. Hope youre finding these sessions enjoyable and informative. Thanks!

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: