The adjectives of the webpage. The skin.
selector {
attribute: value;
otherAttribute: value;
}
Select all instances of a given element.
a {
font-size: 3em;
}
Target an element with a specific ID (only one –unique– ID name per page)
#someId {
text-decoration: none;
}
Selects all elements with a given class
.someClass {
display: absolute;
}
Selects all elements within a given range
* {
border: 1px solid black;
}
Selects an element nested inside another element
li a {
text-decoration: none;
}
Selects an element sibling of another element
h4 + ul {
font-size: 17px;
}
Selects elements with a specific attribute
a[href="http://www.somelink.com/"] {
color: blue;
}
input[type="checkbox"] {
background-color: green;
}
Selects every element within a specific range
ul:nth-of-type(3) {
font-weight: 900;
}
div::after {
margin: 1em;
}
Inline | IDs | Classes | Elements |
0 | 0 | 0 | 0 |
ul {
color: purple;
} // li inside a ul inherit ul style
The closest element to specify an attribute wins
body {
color: red;
} // everything inherits red from body
ul {
color: purple;
} // li inside a ul inherits ul style because it's the closest
In a document, each element is represented as a rectangular box.
In CSS each of these boxes is described using the standard Box Model.
Each box has four edges:
Interrupts the normal document flow and stacks things horizontally instead of vertically
Normal Vertical Flow
Normal Vertical Flow
Added float for Horizontal Flow
Added float for Horizontal Flow
<div class="cf"></div>
.cf:before,
.cf:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.cf:after {
clear: both;
}
Many units for different use-cases. Not all atribbutes accept the same kind of units
red, blue, rebeccapurple, coral
#000000, #FFFFFF, #4B0082
#redgreenblue:______
#RRGGBB - Range: 00-FF
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
0, 1
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
rgb(255,255,255), rgba(0,0,0, 0.9)
rgb(Red, Green, Blue) - Range: 0-255
hsl(210, 100%, 50%), hsla(240, 100%, 50%, .7)
hsl(Hue, Saturation, Light) - Range: 360deg + 0-100%
rgba(0,0,0, 0.9), hsla(240, 100%, 50%, .7)
Range: 0.0-1