CSS - CASCADING STYLE SHEETS
WHAT IS CSS ?
NEED FOR CSS
CSS SYNTAX RULES
selector { property: value; property: value; …}
p.right { text-align: right }
.right { text-align: right }
… in html document: <p class=“right”>Right aligned text</p>
div#green { color: green }
#green { color: green }
… in html document: <div id=“green”>Green div…</div>
A SIMPLE CSS EXAMPLE
body {background-color: #aabbcc}
h1 {font-style: italic; font-size: 36pt}
h2 {color: blue}
p {margin-left: 50px}
PSEUDO-CLASSES
selector:pseudo-class {property: value; …}
selector.class:pseudo-class {property: value; …}
a:link {color:#FF0000} /* unvisited link */�a:visited {color:#00FF00} /* visited link */�a:hover {color:#FF00FF} /* mouse over link */�a:active {color:#0000FF} /* selected link */
PSEUDO-ELEMENTS
selector::pseudo-element {property: value; …}
selector.class::pseudo-element {property: value; …}
div:first-letter { font-size: xx-large; }
div:first-line { color: red }
h1:before { content: url(smiley.jpg)}
h1:after { content: url(smiley.jpg)}
ADDING STYLE SHEETS TO A DOCUMENT
<head>
<link rel=“stylesheet” type=“text/css” href=“style.css”>
</head>
<head>
<style type=“text/css”>
p { margin-left: 10px }
</style>
</head>
<p style=“color: red; margin-left: 10px”}
MULTIPLE STYLE SHEETS
1) browser default
2) external style sheet
3) internal style sheet
4) inline style
BACKGROUND PROPERTIES
Property | Description |
background | Sets all the background properties in one declaration |
background-attachment | Sets whether a background image is fixed or scrolls with the rest of the page |
background-color | Sets the background color of an element |
background-image | Sets the background image for an element |
background-position | Sets the starting position of a background image |
background-repeat | Sets how a background image will be repeated |
BACKGROUND CSS EXAMPLE
div
{�background-color:#0f0f0f;
background-image:url(‘back.jpg');�background-repeat:repeat-x;�background-position:top right;
}
THE CSS BOX MODEL
THE CSS BOX MODEL (2)
Total width=width+left padding+right padding+left border+
right border+left margin+right margin
Total height=height+top padding+bottom padding+top border+ bottom border+top margin+bottom margin
BORDER AND OUTLINE PROPERTIES
Property | Description |
border | Sets all the border properties in one declaration |
border-bottom | Sets all the bottom border properties in one declaration |
border-bottom-color | Sets the color of the bottom border |
border-bottom-style | Sets the style of the bottom border |
border-bottom-width | Sets the width of the bottom border |
border-color | Sets the color of the four borders |
border-left | Sets all the left border properties in one declaration |
border-left-color | Sets the color of the left border |
border-left-style | Sets the style of the left border |
border-left-width | Sets the width of the left border |
border-right | Sets all the right border properties in one declaration |
border-right-color | Sets the color of the right border |
border-right-style | Sets the style of the right border |
border-right-width | Sets the width of the right border |
border-style | Sets the style of the four borders |
border-top | Sets all the top border properties in one declaration |
border-top-color | Sets the color of the top border |
border-top-style | Sets the style of the top border |
border-top-width | Sets the width of the top border |
border-width | Sets the width of the four borders |
outline | Sets all the outline properties in one declaration |
outline-color | Sets the color of an outline |
outline-style | Sets the style of an outline |
outline-width | Sets the width of an outline |
BORDER CSS EXAMPLE
div {
border-top-style: solid;
border-bottom-style: solid;
border-left-style: dotted;
border-right-style: dotted;
border-width: 2px;
border-color: #00ff00;
}
DIMENSION PROPERTIES
Property | Description |
height | Sets the height of an element |
max-height | Sets the maximum height of an element |
max-width | Sets the maximum width of an element |
min-height | Sets the minimum height of an element |
min-width | Sets the minimum width of an element |
width | Sets the width of an element |
FONT PROPERTIES
Property | Description |
font | Sets all the font properties in one declaration |
font-family | Specifies the font family for text |
font-size | Specifies the font size of text |
font-style | Specifies the font style for text |
font-variant | Specifies if a text should be displayed in a small-caps font |
font-weight | Specifies the weight of the font |
FONT CSS EXAMPLE
p, div {
font-family:”Times New Roman”, Arial, Serif;
font-style: italic;
font-size: 12px;
}
LIST PROPERTIES
Property | Description |
list-style | Sets all the properties for a list in one declaration |
list-style-image | Specifies an image as the list-item marker |
list-style-position | Specifies where to place the list-item marker |
list-style-type | Specifies the type of list-item marker |
LIST CSS EXAMPLE
ul {
list-style-type: circle;
list-style-position: inside;
}
MARGIN AND PADDING PROPERTIES
Property | Description |
margin | Sets all the margin properties in one declaration |
margin-bottom | Sets the bottom margin of an element |
margin-left | Sets the left margin of an element |
margin-right | Sets the right margin of an element |
margin-top | Sets the top margin of an element |
padding | Sets all the padding properties in one declaration |
padding-bottom | Sets the bottom padding of an element |
padding-left | Sets the left padding of an element |
padding-right | Sets the right padding of an element |
padding-top | Sets the top padding of an element |
MARGIN CSS EXAMPLE
div {
margin-top: 100px;
margin-bottom: 100px;
margin-left: 5%;
margin-right: 5%;
}
POSITIONING PROPERTIES
Property | Description |
bottom | Sets the bottom margin edge for a positioned box |
clear | Specifies which sides of an element where other floating elements are not allowed |
clip | Clips an absolutely positioned element |
cursor | Specifies the type of cursor to be displayed |
display | Specifies the type of box an element should generate |
float | Specifies whether or not a box should float |
left | Sets the left margin edge for a positioned box |
overflow | Specifies what happens if content overflows an element's box |
position | Specifies the type of positioning for an element |
right | Sets the right margin edge for a positioned box |
top | Sets the top margin edge for a positioned box |
visibility | Specifies whether or not an element is visible |
z-index | Sets the stack order of an element |
TABLE PROPERTIES
Property | Description |
border-collapse | Specifies whether or not table borders should be collapsed |
border-spacing | Specifies the distance between the borders of adjacent cells |
caption-side | Specifies the placement of a table caption |
empty-cells | Specifies whether or not to display borders and background on empty cells in a table |
table-layout | Sets the layout algorithm to be used for a table |
TEXT PROPERTIES
Property | Description |
color | Sets the color of text |
direction | Specifies the text direction/writing direction |
letter-spacing | Increases or decreases the space between characters in a text |
line-height | Sets the line height |
text-align | Specifies the horizontal alignment of text |
text-decoration | Specifies the decoration added to text |
text-indent | Specifies the indentation of the first line in a text-block |
text-shadow | Specifies the shadow effect added to text |
text-transform | Controls the capitalization of text |
vertical-align | Sets the vertical alignment of an element |
white-space | Specifies how white-space inside an element is handled |
word-spacing | Increases or decreases the space between words in a text |
TEXT CSS EXAMPLE
h1 {
color: #00ddee;
text-align: justify;
text-decoration: underline;
text-shadow: 10;
}
DISPLAYING AND VISIBILITY
visibility: hidden;
display: none;
opacity: x – on Firefox, x between 0.0 and 1.0
filter:alpha(opacity=x) – on IE, x between 0 and 100.
POSITIONING
FLOATING