Unit III - Introduction To CSS
Unit III - Introduction To CSS
WHAT IS CSS?
Cascading Style Sheets This is a tool that allows you to specify attributes such as color and font size for all page elements marked by specific tag, name of ID. CSS not only give designers a more efficient way to specify style but also more control over an objects attributes as well as how each object should be displayed in certain situations.
CSS Syntax
A CSS rule has two main parts: a selector, and one or more declarations:
CSS Example
A CSS declaration always ends with a semicolon ;, and declaration groups are surrounded by curly brackets { }:
p {color:red;text-align:center;}
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*/ p { text-align:center; /*This is another comment*/ color:black; font-family:arial; }
Inline Style
An inline style loses many of the advantages of style sheets by mixing content with presentation. Use this method sparingly! To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property.
Inline Style
The example shows how to change the color and the left margin of a paragraph: Sample of Inline Style:
<p style="color:sienna;margin-left:20px">This is a paragraph.</p>
Embedded Style
An embedded 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:
<head> < style> hr {color:sienna;} p {margin-left:20px;} body {background-image:url("images/back40.gif");} < /style> < /head>
External Style
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> < link rel="stylesheet" type="text/css" href="mystyle.css"> < /head>
External Style
In external style, we usually use CLASS and ID.
CLASS is just adding an extension to the typical CSS code and make a specify extension in the HTML, symbol (.) ID is used to specify a style for a single, unique element, symbol (#)
HANDS-ON/MINDS-ON ACTIVITY Creating Web Page with External Style 1. For the second style, type the codes given here. 2. Save your file as Style2.css
IMPORTANT: BE SURE THAT YOU ARE SAVING YOUR FILE IN THE SAME DIRECTORY/FOLDER!
STYLE 1
STYLE 2
STYLE 3
CSS Elements
ELEMENTS A A:ACTIVE A:LINK A:VISITED B BLOCKQUOTE BODY CENTER ELEMENTS ELEMENTS DIV CODE FORM H1-H6 I INPUT LI ELEMENTS HR
OL
SPAN TEXTAREA
P
STRONG TH
PRE
TABLE TR
ABBR
TD UL
CSS Properties
Background:
Background-color color, transparent Background-image URL, none Background-position percentage, length , center Background-attachment scroll, fixed
CSS Properties
Border:
Border-bottom length, color (thin, medium, thick, none, dotted, dashed, solid) Border-bottom-width length, thin, medium, thick Border-color color Border-left length, color (thin, medium, thick,
CSS Properties
Font:
Font-family arial, san serif, monospace, cursive, fantasy etc. Font-size percentage, length, larger, smaller, xxsmall, x-small, small, medium, large, x-large, xx-large Font-style normal, italic, oblique Font-variant normal, small-caps Fornt-weight normal, bolder, bold, lighter, 100, 200, 300, 400, 500, 600, 700, 800, 900
CSS Properties
List:
List-style URL, disc, circle, square, decimal, lowerroman, upper-roman, lower-alpha, upper-alpha, none, inside, outside List-style-image URL, none List-style-position inside, outside List-style-type disc, circle, square, decimal, lowerroman, upper-roman, lower-alpha, upper-alpha, none
Develop a passion for learning. If you do, you will never cease to grow. ~ Anthony J. D'Angelo