1/* this will center all children within the parent element. */
2.parent {
3 display: flex;
4 justify-content: center; /* horizontal */
5 align-items: center; /* vertical */
6}
1IMG.displayed {
2 display: block;
3 margin-left: auto;
4 margin-right: auto }
5 ...
6<IMG class="displayed" src="..." alt="...">
1.parent {
2 position: relative;
3}
4.child {
5 position: absolute;
6 top: 50%;
7 left: 50%;
8 transform: translate(-50%, -50%);
9}
1// example 1
2div { display: grid; place-items: center; }
3
4// example 3
5div{ display:flex; align-items:center; }
6
7// example 3
8div { width: 100%; margin: 0 auto; }