1 CSS
1 CSS
Presented
by
Dr.C.Rani
Assistant Professor
Department of Computer Science and Engineering
Government College of Engineering, Salem-11
1
Objectives and Outcomes
Session Objective
To know the basic concepts of CSS
Session Outcomes
Understand the basic concepts of CSS
2
Cascading Style Sheets (CSS)
Describes the appearance, layout, and
presentation of information on a web page
HTML describes the content of the page
Describes how information is to be
displayed, not what is being displayed
Can be embedded in HTML document or
placed into separate .css file
Basic CSS rule syntax
selector {
property: value;
property: value;
...
property: value;
}
CSS
p {
font-family: sans-serif;
color: red;
}
CSS
A CSS file consists of one or more rules
Each rule starts with a selector
A selector specifies an HTML element(s) and then applies style
properties to them
a selector of * selects all elements
Embedding style sheets:
<style>
<head>
<style type="text/css">
p { font-family: sans-serif; color: red; }
h2 { background-color: yellow; }
</style>
</head>
HTML
CSS
This paragraph uses the style above
output
property description
color color of the element's text
color that will appear behind
background-color
the element
Specifying colors
p { color: red; }
h2 { color: rgb(128, 0, 196); }
h4 { color: #FF8800; }
CSS
output
A style can select multiple elements separated by
commas
The individual elements can also have their own
styles
CSS comments /*…*/
/* This is a comment.
It can span many lines in the CSS file. */
p {
color: red; background-color: aqua;
} CSS
output
We can specify multiple fonts from highest to lowest priority
Generic font names:
serif, sans-serif, cursive, fantasy, monospace
If the first font is not found on the user's computer, the next is tried
Placing a generic font name at the end of your font-family value, ensures that every
computer will use a valid font
font-size
p {
font-size: 24pt;
} CSS
output
CSS properties for text
property description
alignment of text within its
text-align
element
decorations such as
text-decoration
underlining
line-height,
gaps between the various
word-spacing,
portions of the text
letter-spacing
indents the first letter of each
text-indent
paragraph
text-align
blockquote { text-align: justify; }
h2 { text-align: center; }
CSS
We wants it, we needs it. Must have the precious. They stole it from us.
Sneaky little hobbitses. Wicked, tricksy, false!
output
text-align can be left, right, center, or
justify
text-decoration
p {
text-decoration: underline;
}
CSS
This paragraph uses the style above.
output
• can also be overline, line-through, blink, or
none
• effects can be combined:
text-decoration: overline underline;
The list-style-type property
ol { list-style-type: lower-roman; }
CSS
CSS
This is a heading
A styled paragraph. Previous slides are available on the website.
• A bulleted list
output
when multiple styles apply to an element, they
are inherited
a more tightly matching rule can override a more
general inherited rule
Styles that conflict
p, h1, h2 { color: blue; font-style: italic; }
h2 { color: red; background-color: yellow; }
CSS
This paragraph uses the first style above.
This heading uses both styles above.
output
pseudo-classes
CSS Syntax:
Selector Strings
Source anchor elements: