CSSC1
CSSC1
I. Syntaxe
example
selector {
property: value;
property: value; body {
} color:darkolivegreen;
background-color: beige;
}
II. Selectors
1. simple selectors Combinator selectors
CSS C1 1
III. How to
Three ways to insert CSS:
External CSS
<link rel="stylesheet" href="mystyle.css">
change the look of a website
with one file
Internal CSS
each html page must include a
defined within the <style>
reference to the external style
element inside the <head>
sheet file inside the <link>
section of an html page element inside the head section
<head>
body {
<style>
background-color: lightblue;
body {
}
background-color: linen;
}
h1 {
color: navy;
h1 {
margin-left: 20px;
color: maroon;
}
margin-left: 40px;
}
</style>
</head>
Inline CSS
add the style attribute to the relevant element. The style attribute can
contain any CSS property.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
CSS C1 2
If some properties have been defined for the same selector (element) in
different style sheets, the value from the last read style sheet will be used
Cascading order
order of priority:
1. Inline style
3. Browser default
V. CSS colors
CSS color names
In CSS, a color can be specified by
background colour
using a predefined color name (like
Tomato, Orange, Gray…)
<h1 style="background-color: DodgerBlue;">Hello World
color values
colors can alo be specified using RGB values, HEX values, HSL values, RGBA
values and HSLA values:
for hex and rgb, for shades of grey, use 3 times the same values.
CSS C1 3
3 digits in hex means 3 times the same double digits
rgb(0,0,300)
#ff6347
hsl(9,100%,64%)
Transparency
0 is completely transparent
HSLA(9,100%,64%,0.5)
selector {
background-image: url("nameofimage.extension");
}
background-repeat property
⬆️ or only vertically/*shows
⬇️ */ the image only once*/
background-repeat: repeat-x; background-repeat: no-repeat;
/* repeat the image only horizontally
background-repeat: repeat-y;
CSS C1 4
top , right , bottom , left , and
background-attachment: fixed;
center : These keywords /* or */
specify the position of the background-attachment: scroll;
2. Percentage Values:
3. Length Values:
4. Multiple Values:
CSS C1 5
You can combine percentage
and keyword values to
specify a position relative
to the keyword value. For
example, background-position: right
20%; will position the image
at the vertical center and
20% from the right.
6. Inverted Values:
background-position: center;
(horizontal centered)
(centered both
horizontally and at the
top)
8. Global Values:
CSS C1 6
background shorthand
background-image
background-repeat
background-attachment
background-position
- Defines a 3D grooved
groove to obtain rounded borders
border. The effect depends on border-radius: 5px;
CSS C1 7
The border-style property can have from
one to four values (for the top
border, right border, bottom border,
and the left border). for example:
border-color
The color can be set by: Note: If border-color is not set, it
inherits the color of the element.
name - specify a color name, like
"red" and like border-style , The border-
transparent
border-width
border-style (required)
border-color
margin-top
CSS C1 8
margin-right auto (the browser calculates the
margin)
margin-bottom
Shorthand property
2 values
1 value
Margin collapse
If there is a bottom margin of an element followed by a top margin of an
element underneath, there is only one margin used and it is the largest one.
Note: this only happens with top/bottom margins
CSS C1 9