Ascading Tyle Heet
Ascading Tyle Heet
Introduction to CSS
CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML to solve a problem External Style Sheets can save a lot of work External Style Sheets are stored in CSS files
HTML was never intended to contain tags for formatting a document. HTML was intended to define the content of a document, like:
cont.
When tags like <font>, and color attributes were added to the HTML, it started a nightmare for web developers. Development of large web sites, where fonts and color information were added to every single page, became a long and expensive process.
cont.
To solve this problem, the World Wide Web Consortium (W3C) created CSS. In HTML, all formatting could be removed from the HTML document, and stored in a separate CSS file. All browsers support CSS today.
CSS defines HOW HTML elements are to be displayed. Styles are normally saved in external .css files. External style sheets enable you to change the appearance and layout of all the pages in a Web site, just by editing one single file.
CSS Syntax
A CSS rule has two main parts: a selector, and one or more declarations:
cont.
The selector is normally the HTML element you want to style. (background,p,h1 etc.) Each declaration consists of a property and a value. (color, size, alignment etc.) The property is the style attribute you want to change. Each property has a value.
CSS Example
A CSS declaration always ends with a semicolon, and declaration groups are surrounded by curly brackets:
p {color:red;text-align:center;}
cont.
To make the CSS more readable, you can put one declaration on each line, like this:
p { color:red; text-align:center;
CSS Comments
Comments are used to explain your code, and may help you when you edit the source code at a later date. Comments are ignored by browsers. A CSS comment begins with "/*", and ends with "*/", like this:
/*This is a comment*/
cont.
p {
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:
cont.
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
background-image:url("images/back40.gif");
}
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> tag, like this:
cont.
<head> <style type="text/css"> hr {color:sienna;} p {margin-left:20px;} body {
background-image:url("images/back40.gif");
} </style> </head>
Inline Styles
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:
<p style="color:sienna;margin-left:20px">
CSS Background
CSS background properties are used to define the background effects of an element.
Background Color
The background-color property specifies the background color of an element. The background color of a page is defined in the body selector: body {background-color:#b0c4de;} With CSS, a color is most often specified by:
a HEX value - like "#ff0000" an RGB value - like "rgb(255,0,0)" a color name - like "red"
cont.
h1 {background-color:#6495ed;} p {background-color:#e0ffff;} div {background-color:blue;}
Background Image
The background-image property specifies an image to use as the background of an element. By default, the image is repeated so it covers the entire element. The background image for a page can be set like this:
body {background-image:url('paper.gif');}
repeat - The background image will be repeated both vertically and horizontally. This is default repeat-x - The background image will be repeated only horizontally repeat-y - The background image will be repeated only vertically no-repeat - The background-image will not be repeated inherit - Specifies that the setting of the background-repeat property should be inherited from the parent element
Background-position
Sets the starting position of a background image. body { background-image:url('img_tree.png'); background-repeat:no-repeat; background-position:right top; }
cont.
left top left center left bottom right top right center right bottom center top center center center bottom
Background-attachment
Sets whether a background image is fixed or scrolls with the rest of the page
background-attachment Properties
scroll - The background image scrolls with the rest of the page. This is default. fixed - The background image is fixed.