Step 3: 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.
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.
|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
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="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.
We value your feedback!
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.
Post a Comment
Creating Responsive Templates
Introduction to Responsive Web Design
|1.||Introduction: Creating a Responsive Web Design|
Creating a Custom Responsive Template
|2.||Step 1: Adding HTML to the Responsive Template|
|3.||Step 2: Adding CSS styles to a Responsive Template|
|4.||Step 3: Links to the stylesheets in Responsive Templates|
|5.||Step 4: Adding the Viewpoint Meta Tag to the Responsive Template|
Customize the look of your Responsive Template
|6.||Responsive template design with the jQuery Theme Roller|
|7.||Styling a Responsive Template with jQuery Theme Roller|
|8.||Custom CSS Styles with the Bootstrap Theme Roller|
|9.||Adding the Bootstrap files to your Responsive Template|
|10.||Adding the Bootstrap Menu Buttons to your Responsive Template|
|11.||Twitter Bootstrap Common classes and HTML styles|
Free Responsive Web Design Themes
|12.||Free Responsive Templates with jQuery Theme Roller styles|