Different ways that styles can be added to a web page
THREE WAYS TO INSERT
CSS
When a browser reads a style
sheet, it will format the document according to it.
There are three ways of
inserting a style sheet:
·
External style sheet
·
Internal style sheet
·
Inline style
We will explain the
differences.
EXTERNAL STYLE SHEET
An external
style sheet is ideal when the style is applied to many pages. With an external
style sheet, you can change the look of an entire Web site by changing one
file. Each page must link to the style sheet using the <link> tag. The
<link> tag goes inside the head section:
<head>
<title>My web page</title>
<link rel="stylesheet" type="text/css" href="/css/template.css">
</head>
<title>My web page</title>
<link rel="stylesheet" type="text/css" href="/css/template.css">
</head>
An external style sheet can be written in any text editor.
The file should not contain any html tags.
Your style sheet should be saved with a .css extension. In most modern websites all css files are contained within a "css" folder. This is for clarity and ease of use, making it simpler to locate the files when needed.
Save the HTML
file. This now links to the CSS file. You will be able to add to and change the
CSS file and see the results by simply refreshing the browser window.
INTERNAL STYLE SHEET
An internal
style sheet should be used when a single document has a unique style. You
define internal styles in the head section of an HTML page, by using the
<head>
<style>
hr { color:sienna; }
p { margin-left:20px; }
body { background-image:url("images/background.gif"); }
</style>
</head>
<style>
hr { color:sienna; }
p { margin-left:20px; }
body { background-image:url("images/background.gif"); }
</style>
</head>
Internal style
sheets are great for websites that have different styling requirements for each
page, or for styling a particular element within a page.
INLINE STYLES
An inline style
loses many of the advantages of style sheets by mixing content with
presentation. Use this method AS A LAST RESORT!
To use inline styles you use the style attribute in the relevant tag.
To use inline styles you use the style attribute in the relevant tag.
<div style="
" ><p>This is a paragraph within a div
tag.</p></div>
The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a paragraph:
So when you
eneter your styling it will look like this:
<div style="color:#FFFFFF;
margin-left:20px;"><p>This is a paragraph
within a div tag.</p></div>
Generally
speaking we can say that all the styles will "cascade" into a new
"virtual" style sheet by the following rules, where number four has
the highest priority:
1.
Browser default
2.
External style sheet
3.
Internal style sheet (in the head section)
4.
Inline style (inside an HTML element)
So, an inline
style (inside an HTML element) has the highest priority, which means that it
will override a style defined inside the <head> tag of a web page, or in
an external style sheet, or in a browser (a default value).
No comments:
Post a Comment