1// add to the parent element
2.parent {
3 display: grid;
4 place-items: center;
5}
1<!--
2 Simple CSS CENTER DIV Example
3
4 * See Fiddle in link for PoC *
5-->
6
7<div class="parent">
8 <div class="child">
9 <p>
10 Eh Up Me Duck!
11 </p>
12 </div>
13</div>
14
15<style>
16.parent {
17 /* Just for aesthetics: see fiddle */
18 border: 1px solid black;
19 padding: 2px;
20}
21
22.child {
23 border: 1px solid red;
24 width: 50%;
25
26 /* This is where the magic happens */
27 margin-left: auto;
28 margin-right: auto;
29 /**********************************/
30}
31
32p {
33 /* As you do */
34 text-align: center;
35}
36</style>