summaryrefslogtreecommitdiff
path: root/3 Resources/CSS.md
blob: 32a31130b524e502dfe8880fbe788ad3ba3daab6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
**Display**
display none vs visibility hidden: display: none is really like the element does not exist. Visibility hidden just hides it but it still takes space.

A display: none element can still have size and be coloured with a background image. It still doesn't take space. This can be used for a timeline bar for example!

**Flexbox**
Flexbox deals with layout always in only one dimension; it's possible to specify which dimension: either vertical or horizontal.

Two axes: main and cross

Control main axis: `flex-direction: row|row-reverse|column|column-reverse`. The first two make it a horizontal layout and the latter make it a vertical layout.

Cross axis is always the opposite of `flex-direction`, so if `flex-direction: row-reverse` the cross axis is `column-reverse`.

The writing mode determines where the start and end are, based on for example languages. Japanese is written from right-to-left rather than western left-to-right.
So while in Europe the start of a flexbox is at the left and the end at the right in Japan this would be reversed.

**Relationships**
An important aspect of creating layouts with CSS is the relationships of elements with each other. For example parent/child relationships.

If we change the width of a parent element; the height of all children increase. This happens because the total area of the parent remains the same.

When the edge of a child aligns with its parent and we add a margin to the child; it pushes to the parent as well. This phenomenon is called ==collapsing margins==. It can be prevented by unaligning the edge(s) for example by adding padding or setting `display: flow-root;`.

In `flexbox` siblings push against each other; if we add padding to one, it pushes against the other making it smaller. This does not happen in grid, where each cell gets a fixed size and the padding pushes against its own side.

**Centering stuff**
Use `margin-inline: auto;` -> this adds margins on both sides of the element. This can be used to center stuff on the page for example.