Css Note
Css Note
Css Note
2
3
What is CSS?
4
p {
font-family: sans-serif;
color: red;
} CSS
A CSS file consists of one or more rules
Each rule starts with a selector
Three ways of adding Style sheets to a web page
1. Inline styles:
Styles are embedded right within the html code
they affect.
<p style="font-family: Lucida-Handwriting; color: red;">
This is a paragraph</p>
HTML
This is a paragraph
output
2. Internal style sheets: <style>
9
<head>
<style type="text/css">
p { font-family:sans-serif; color: red; }
h2 { background-color: yellow; }
</style>
</head>
HTML
3. External/Attaching a CSS file <link>
10
Styles are coded in a separate document, which is then
referenced/linked from within the header of the actual web
page.
<head>
...
<link href="filename" type="text/css" rel="stylesheet" />
...
</head> HTML
p {
color: red;
background-color: yellow;
}
CSS
PROPERTY DESCRIPTION
color color of the element's text
color that will appear behind the
background-color
element
Grouping styles
12
p, h1, h2 {
color: green;
}
h2 {
background-color: yellow;
} CSS
Body
{
Background-image
background-image: url (“tashi.jpg”);
}
CSS
PROPERTY DESCRIPTION
background-image To insert an image in a webpage
Background-color To apply background color to HTML element.
To repeat the background image, value can be as below
repeat-x (repeated horizontally)
Background-repeat repeat-y (repeated vertically)
repeat (repeated horizontally and vertically)
no-repeat (image is not repeated at all)
Background shorthand for all the background properties
{background-color background-image background-repeat;}
e.g. Body { background: green url(baby.jpg) no-repeat; }
3. CSS properties for fonts
14
PROPERT
DESCRIPTION
Y
font-family which font will be used
how large the letters will be drawn ( Specify in px(pixel),
font-size
pt(Point-size, %(percentage), em)
font-style used to enable/disable italic style. Value(normal/italic)
It specifies the boldness or heaviness for a font.
font-weight
Value (Normal /bold/bolder/lighter/100-900)
h1 {
font-family: Algerian; Verdana; font-sze:20px; font-style: italic;
font- weight: bold;
}
4.CSS properties for text
15
property description
alignment of text within its element.
text-align
VALUE (left/right/center/justify)
text-decoration to add effects to text. VALUE(underline/overline/line-through)
word-spacing,
gaps between the various portions of the text
letter-spacing
text-indent blank space before the first letter of each paragraph
control appearance of text in different cases.
Text-transform
VALUE(capitalize/uppercase/lowercase/none)
P{ text-align: center;
text-decoration: overline;
text-transform: capitalize;
}
5. CSS properties for Margins and padding
16
18
PROPERTY VALUE
Border-width thin/medium/thick e.g. h1 { border-width: thick ;}
Border-color Color name e.g. h3{border-color: green;}
Border-style dotted/ dashed /solid / double /groove/ ridge / inset / outset
e.g. h2{border-style: double;}
/* This is a comment.
It can span many lines in the CSS file. */
p {
color: red; background-color: aqua;
} CSS
The <!-- ... --> HTML comment style is also NOT supported in
CSS