Skip to content

Commit c97df3e

Browse files
author
PB Sweep
committed
Add css_fundamentals.md
1 parent b2cf41b commit c97df3e

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

notes/css_fundamentals.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# CSS Fundamentals
2+
3+
## CSS Selectors
4+
5+
```css
6+
/* All selector */
7+
* { /* select all elements */
8+
9+
}
10+
11+
/* Element selector */
12+
p { /* selects all <p> elements */
13+
14+
}
15+
16+
h1, h2 { /* Selects all <h1> and all <h2> elements */
17+
18+
}
19+
20+
div p { /* Selects all <p> elements inside <div> elements */
21+
22+
}
23+
24+
div > p { /* Selects all <p> elements where the parent is a <div> element */
25+
26+
}
27+
28+
div + p { /* Selects the first <p> element that is placed immediately after <div> elements */
29+
30+
}
31+
32+
p ~ ul { /* Selects every <ul> element that is preceded by a <p> element */
33+
34+
}
35+
36+
/* class selector, uses . prefix */
37+
.intro { /* selects all class="intro"*/
38+
39+
}
40+
41+
.intro.part1 { /* Selects all elements with both "intro" and "part1" set within its class attribute */
42+
43+
}
44+
45+
.intro .part1 { /* Selects all elements with "part1" that is a descendant of an element with "intro" */
46+
47+
}
48+
49+
/* id selector, uses # prefix */
50+
#id1 { /* selects all id="id1" */
51+
52+
}
53+
54+
p.intro { /* Selects all <p> elements with class="intro" */
55+
56+
}
57+
58+
```
59+
60+
## General points
61+
62+
Font properties are generally inherited (e.g. `font-family`, `font-size` etc.)
63+
64+
`background-color`: sets the color of the background
65+
66+
`color`: sets the font color
67+
68+
`border`: it's a shorthand property (set multiple values: width (e.g. 5px), style (e.g. solid) and color (e.g. red))
69+
70+
## Box Model
71+
72+
Each element is a box with width, height, padding, margin, border and fill area (all are optional).
73+
74+
- Content: contains the content of the box
75+
- Padding: transparent area around the content; inside of the box.
76+
- Border: goes around the padding and the content
77+
- Margin: space between boxes; outside of the box.
78+
- Fill area: Area that gets filled with background color or background image
79+
80+
### `box-sizing: border-box;`
81+
82+
The `box-sizing: border-box;` CSS property changes how the width and height of an element are calculated. By default, an element's width and height are calculated based on the content box, meaning padding and borders are not included in the width or height.
83+
84+
When you set box-sizing: border-box;, the element's padding and border are included within the specified width and height. This means that if you set an element to be width: 100px and height: 100px, and it has padding: 10px and a border: 1px all around, the total width and height will still be 100px each, not 122px (which would be the case with the default content-box model).

0 commit comments

Comments
 (0)