Thursday, May 15, 2014

How to include CSS

// // Leave a Comment

There are four ways to associate styles with your HTML document. Most commonly used methods are inline CSS and External CSS.
  1. Inline Style
  2. Internal Style Sheet
  3. External Style Sheet
  4. Import Style Sheet
External Style Sheet:
An external style sheet is ideal when the style is applied to many pages.
External style sheet include using <link> tag. The <link> tag goes inside the head section.

<head>
<link type=”text/css” rel=”stylesheet” href=”style.css” />
</head>
Your style sheet should be saved with a .css extension Example: style.css
Internal Style Sheet:
An style sheet should be used when a single document has a unique style. Internal style sheet using inside head section.
Example:
<head>
<style type=”text/css”>
.paragraph{ color:red: text-align:center; }
</style>
</head>
Inline CSS
Inline Style use the style attribute in the revelant tag.
Example:
<h1 style=”color:blue; font-size:20px”>Hello world!</h1>

Imported CSS - @import Rule:

@import is used to import an external stylesheet in a manner similar to the <link> element. Here is the generic syntax of @import rule.
<head>
<@import "URL";
</head>
Here URL is the URL of the style sheet file having style rules. You can use another syntax as well:
<head>
<@import url("URL");
</head>

Example:

Following is the example showing you how to import a style sheet file into HTML document:
<head>
@import "mystyle.css";
</head>

0 comments:

Post a Comment