In this Tutorial Describe Types of CSS Basically we define 3 types of CSS see above-
Inline CSS -
In This CSS we add inline style.
Inline styles are styles that are written directly in the tag like div,textbox button etc. Inline styles affect only the tag they are applied to and not effect other tag untill unless not match same name and id of tag other wise apply both if match 2 tag's same name then.
To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. See in Above Example-
An internal style sheet should be used when a single document has a unique style. You
define internal styles in the head section by using the <stye type="text/css"> Select : Property
</style>
The browser will now read the style definitions, and format the document according to it.
Note: A browser normally ignores unknown tags. This means that an old browser that
does not support styles, will ignore the <style> tag, but the content of the <style> tag will
be displayed on the page. It is possible to prevent an old browser from displaying the
content by hiding it in the HTML comment element:
<head>
<style type="text/css">
<!--
hr {color: sienna}
p {margin-left: 20px}
body {background-image: url("images/back40.gif")}
-->
</style>
</head>
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
Example
The browser will read the style definitions from the file styles.css, and format the- Inline CSS
- Internal (embedded) CSS
- External CSS
Inline CSS -
In This CSS we add inline style.
Inline styles are styles that are written directly in the tag like div,textbox button etc. Inline styles affect only the tag they are applied to and not effect other tag untill unless not match same name and id of tag other wise apply both if match 2 tag's same name then.
To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. See in Above Example-
Example Inline CSS
<!DOCTYPE html>
<html>
<body>
<div style="background-color:wheat;width:200px;height:50px;border:1px solid" >
</div>
</body>
</html>
Output- <html>
<body>
<div style="background-color:wheat;width:200px;height:50px;border:1px solid" >
</div>
</body>
</html>
Internal (embedded) CSS
Embeddded style are written on same page in head section we define all css properties and that is reflected only this page where we define internal css.An internal style sheet should be used when a single document has a unique style. You
define internal styles in the head section by using the <stye type="text/css"> Select : Property
</style>
Example Internal CSS
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.inlinecss {
background-color:wheat;
width:300px;
height: 50px;
border:1px solid;
}
</style>
</head>
<body>
<div class="inlinecss">
</div>
</body>
</html>
Output- <html>
<head>
<style type="text/css">
.inlinecss {
background-color:wheat;
width:300px;
height: 50px;
border:1px solid;
}
</style>
</head>
<body>
<div class="inlinecss">
</div>
</body>
</html>
The browser will now read the style definitions, and format the document according to it.
Note: A browser normally ignores unknown tags. This means that an old browser that
does not support styles, will ignore the <style> tag, but the content of the <style> tag will
be displayed on the page. It is possible to prevent an old browser from displaying the
content by hiding it in the HTML comment element:
<head>
<style type="text/css">
<!--
hr {color: sienna}
p {margin-left: 20px}
body {background-image: url("images/back40.gif")}
-->
</style>
</head>
External CSS
External styles are styles that are written in a separate document and then attached to various Web documents. External style sheets can affect any document they are attached to.We add external style sheet then attach on each page you want to attach and reflect those page. Use external sheet then no need internal and inline css and want common for whole site. This is easy to maintain for website.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
Example
<link rel="stylesheet" type="text/css" href="styles.css" />
Note-> In this Styles.css file we write all styles in styles.css file. Give link on page where we want.
Note-> In this Styles.css file we write all styles in styles.css file. Give link on page where we want.
document according to it.You can write css style whatever you write all styles in this file.
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. An example of a style
sheet file is shown below:
hr {color: sienna}
p {margin-left: 20px}
body {background-color:blue;}
Note - Do NOT leave spaces between the property value and the units! If you use "marginleft:
20 px" instead of "margin-left: 20px" it will only work properly in IE6 but it will not
work in Mozilla/Firefox or Netscape.
Multiple Style Sheets
If some properties have been set for the same selector in different style sheets, the values will be inherited from the more specific style sheet.For example, an external style sheet has these properties for the h3 selector:
h3 {
color: red; text-align: left; font-size: 8pt;
}
And an internal style sheet has these properties for the h3 selector:
h3
{
text-align: right; font-size: 20pt;
}
If the page with the internal style sheet also links to the external style sheet the properties for h3 will be:
color: red; text-align: right; font-size: 20pt
The color is inherited from the external style sheet and the text-alignment and the fontsize is replaced by the internal style sheet.
0 comments :
Post a Comment