Basic syntax
p {
comment syntax
/* comment here */
Block style
surrounds portions of code in curly braces
Selector
Property
identifies which component to change
Value
specifies the value of the attribute
Declaration
indicates a property/value pair
Class selector
- use a period before class name
ID selector
- use # pound symbol before class name
Universal selector
- use * symbol
Selecting multiple elements
ex: html, body, h1, p {
//apply CSS here
}Parent-child selector
ex: div > p {
}
Ancestor-descendant selector
-selects all matching descendants of an element (general descendants)
-use a space between two selectors
ex: div p {
}
Sibling selector
Predecessor/Successor selector
Combining selectors
Specifying color
Examples:
name(red) hex-value (#FF0000) rgb (255,0,0) rgba (255,0,0,1) hsl(360,100%,100%) hsla(360,100%,100%,1)
Specifying color (hexadecimal)
Specifying color (rgb)
Specifying color (rgba)
-4th value between 0 and 1 indicate level of transparency
Specifying color (hsl)
-specify a color in terms of hue, saturation (%) and lightness (%)
Specifying color (hsla)
-alpha value as a -4th value between 0 and 1 indicate level of transparency
Background property
Background shorthand
-applies multiple properties in a single statement
-ex:
div {
background: url(“bg.jpg”) #0000ff top right;
}