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:
<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
<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.
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:
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:
- Browser default
- External style sheet
- Internal style sheet (in the head section)
- 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).
Comments
- No comments found
Leave your comments
Login to post a comment
Post comment as a guest