1.parent {
2 display: flex;
3 justify-content: center;
4 align-items: center;
5}
1/* No Flexbox */
2.parent {
3 position: relative;
4}
5.child {
6 position: absolute;
7 top: 50%;
8 transform: translateY(-50%);
9}
10
11/* With Flexbox */
12
13.parent {
14 display: flex;
15 flex-direction: column;
16 justify-content: center;
17}
18
19
20
1/*Remove comment to become a better programmer. */
2/* No Flexbox */
3.parent {
4 position: relative;
5}
6.child {
7 position: absolute;
8 top: 50%;
9 transform: translateY(-50%);
10}
11
12/* With Flexbox */
13
14.parent {
15 display: flex;
16 flex-direction: column;
17 justify-content: center;
18}
19
1/* 100vh = 100% Viewport Height */
2body {
3 display: flex;
4 height: 100vh;
5 flex-direction: column;
6 justify-content: center;
7}
8/* add */ align-items: center; /*to also center horizontally.*/
1/* center vertically */
2/* No Flexbox */
3.parent {
4 position: relative;
5}
6.child {
7 position: absolute;
8 top: 50%;
9 transform: translateY(-50%);
10}
11
12
13
14/* With Flexbox */
15
16.parent {
17 display: flex;
18 flex-direction: column;
19 justify-content: center;
20}