01 Intro to CSS.pptx
01 Intro to CSS.pptx
2
CSS
Each rule is composed by 2 parts:
❑ the selector
❑ the declaration block
3
CSS
Selector is a string that identifies one or more
elements on the page, following a special syntax that
will soon talk about extensively.
4
Introduction to CSS
How does CSS look like
How does CSS look like
A CSS rule set has one part called selector, and the
other part called declaration. The declaration
contains various rules, each composed of a
property, and a value.
7
CSS BASIC SYNTAX
CSS Basic Syntax
selector { body {
property: value; background-color: cyan;
} }
p{
font-size: 20px;
}
10
Multiple rules are stacked one after the other:
h1 {
font-size: 20px;
}
p{
color: blue;
}
11
A selector can target one or more items:
h1, p {
font-size: 20px;
}
12
Semicolons
Semicolons (;)
14
Semicolons (;)
❌ Wrong ✅ Correct
p{ p{
color: blue color: blue;
font-size: 16px font-size: 16px;
} }
15
Formatting &
Indentation
Formatting and Indentation
There is no fixed rule for formatting. This CSS is
valid:
p{ p {font-size: 20px;}
font-size: 20px;}
a{
a {color: blue; color: blue;
} }
17
Adding CSS
to an HTML page
Using the link tag
Using the link tag
The <link> tag connects your HTML file to a separate
CSS file.
╺ Instead of writing CSS on every page, you write it
once in a separate file.
╺ If you change one line in the CSS file, it updates
the whole website!
<style>
...our CSS...;
</style>
23
Inline Styles
Inline Styles
Inline styles are the third way to add CSS to a page.
We can add an attribute to any HTML tag and add
CSS to it.
<p style="">...</p>
Example:
<p style="background-color: yellow">...</p>
25
CSS COMMENTS
CSS Comments
Single Line Multiple Line
CSS Comments 27
28
Next Class
29
30
CSS SELECTORS
CSS Selectors
CSS selectors are used to "find" (or select) the HTML elements you want to style.
CSS Selectors 32
CSS Selectors
are used to "find" (or select) the HTML elements you want to style.
CSS Selectors 33
CSS element Selector
❑ The element selector selects HTML elements based on the element
name.
Example
❑ Here, all <p> elements on the
page will be center-aligned,
with a red text color:
Example
❑ In this example all HTML
elements with class="center"
will be red and center-aligned:
Example
❑ In this example only <p>
elements with class="center"
will be red and center-aligned:
CSS Selectors > class Selector 42
CSS class Selector
Example
❑ In this example the <p> element will be styled according to
class="center" and to class="large":
Example
❑ The CSS rule below will affect
every HTML element on the page: