Continuing our tutorial on how to create a Responsive Template, we are moving to step 3 of the process where we add the CSS links to the stylesheets on the head section. The previous tutorial explained what you need to create for the CSS stylesheets. This tutorial will explain how to link your stylesheets to your HTML document.

Link for the main stylesheet

To get the general styles to work on your website, you will need to link to the file. Below is the code for the link to the style.css file.

<link rel="stylesheet" href="style.css" />

Using CSS Media attribute

Link for the Desktop Styles

The first style sheet will need to load when the browser size is the typical Desktop computer monitor size. Lately, wide screen monitors are popular, so we will have the large styles load when the browser is larger than 1440 pixels. Below is the link to the desktop-style.css stylesheet from the previous tutorial. You place the code in the head section of your site.

<link rel="stylesheet" media="screen and (min-device-width: 1440px)" href="desktop-style.css" />

The min-device-width is set to 1440px to make the desktop-style.css sheet load when the browser size is at 1440 pixels.

Link for the Tablet Styles

When the browser window goes below 1440 pixels, the medium stylesheet will load. The minimum width is 800 pixels before it will switch to the mobile stylesheet. Below is the code that goes in the head section for your medium-style.css stylesheet for tablets and smaller screens.

<link rel='stylesheet' media='screen and (min-width: 800px) and (max-width: 1439px)' href='medium-style.css' />

Now when the browser goes from a minimum of 800 pixels to a maximum 1439 pixels, the medium-styles.css sheet will load.

Link for the Mobile Styles

The mobile style sheet will be set up to load when the width is a minimum width of 100 pixels and a maximum width of 799 pixels. This will make the website adjust to the mobile version when the width goes under 800 pixels. We will use the following link to the mobile-style.css stylesheet.

<link rel='stylesheet' media='screen and (min-width: 100px) and (max-width: 799px)' href='mobile-style.css' />

This code will load the mobile-styles.css sheet when the browser is below 799 pixels. The style sheet will stop shrinking at 100 pixels.

CSS Media Attributes explained

Below is a brief explanation of what each attribute does.

Feature Description
width The width of the browser window area.
height The height of the browser window area.
min-width The minimum width of the browser window area.
max-width The maximum-width of the browser window area.
device-width The width of the device's entire display area regardless of browser window width.
min-device-width The minimum width of the device's entire display area regardless of browser window width.
max-device-width The maximum width of the device's entire display area regardless of browser window width.
device-height The height of the device's entire display area regardless of browser window height.
orientation The orientation of the device whether "landscape" or "portrait".
aspect-ratio Detects the aspect ratio of the "browser width" to "browser height" of the media. Example 2/1
device-aspect-ratio Detects the ratio of value of the "device width"to "device height" media.
color Number of bits per color component of the device.
color-index Number of entries in the color lookup table of the output device.
monochrome Number of bits per pixel in a monochrome frame buffer.
resolution The "dpi" or "dpcm" resolution on the device.
scan The scanning process of a "tv".
grid Detects whether the device is grid or bitmap.

The entire code for the head section

ResponsiveTemplate with stylesOnce you understand how the stylesheets will load, you can add the code to your website. The below code is the entire head section you will need at the top of your HTML code. The links to the stylesheets are in red. Copy the following code and place it at the top of your HTML code.

<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Fluid Responsive Template</title>
 <link rel="stylesheet" href="style.css" />
 <link rel="stylesheet" media="screen and (min-device-width: 1440px)" href="style.css" /> 
 <link rel='stylesheet' media='screen and (min-width: 800px) and (max-width: 1440px)' href='medium-style.css' />
 <link rel='stylesheet' media='screen and (min-width: 100px) and (max-width: 799px)' href='mobile-style.css' />
</head>

Now that you have the code for the stylesheets and the HTML you will need to add the Viewpoint META tag for the mobile devices to accept the styles.

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Like this Article?

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!