css margin to center code example
Example 1: css center
/* this will center all children within the parent element. */
.parent {
display: flex;
justify-content: center; /* horizontal */
align-items: center; /* vertical */
}
Example 2: centering horizontally
div.center{display:block;margin:auto;width:50%;}
p.center{text-align:center;}
Example 3: css center div
<div class="parent">
<div class="child">
<p>
Eh Up Me Duck!
</p>
</div>
</div>
<style>
.parent {
border: 1px solid black;
padding: 2px;
}
.child {
border: 1px solid red;
width: 50%;
margin-left: auto;
margin-right: auto;
}
p {
text-align: center;
}
</style>