Links to the stylesheets in Responsive Templates

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.

Launch your web presence quickly and easily with Shared Hosting. Our user-friendly hosting is perfect for everyone, providing the fastest shared hosting experience possible, all powered by cPanel.

check markFree Domain & SSL Certificates check markUnlimited Bandwidth check mark400+ One-Click Applications check markUSA & European Data Centers

Shared Hosting Plans

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

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.

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.

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.

CSS AttributeWhat the Attribute Does
widthThe width of the browser window area.
heightThe height of the browser window area.
min-widthThe minimum width of the browser window area.
max-widthThe maximum-width of the browser window area.
device-widthThe width of the device’s entire display area regardless of browser window width.
min-device-widthThe minimum width of the device’s entire display area regardless of browser window width.
max-device-widthThe maximum width of the device’s entire display area regardless of browser window width.
device-heightThe height of the device’s entire display area regardless of browser window height.
orientationThe orientation of the device whether “landscape” or “portrait“.
aspect-ratioDetects the aspect ratio of the “browser width” to “browser height” of the media. Example 2/1
device-aspect-ratioDetects the ratio of value of the “device width“to “device height” media.
colorNumber of bits per color component of the device.
color-indexNumber of entries in the color lookup table of the output device.
monochromeNumber of bits per pixel in a monochrome frame buffer.
resolutionThe “dpi” or “dpcm” resolution on the device.
scanThe scanning process of a “tv“.
gridDetects whether the device is grid or bitmap.

The entire code for the head section

ResponsiveTemplate with styles

Once 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="https://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Your Website Title</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.

Share this Article