center a element css code example
Example 1: center a div in css
.container {
display: flex;
justify-content: center;
align-items: center;
}
Example 2: css align items vertical center
.parent {
display: flex;
justify-content: center;
align-items: center;
}
Example 3: how to center a div element
.box1{
width:80%;
margin:0 auto;
}
Example 4: center css elements
body{
display: grid;
place-items: center;
}
Example 5: css center div
<!--
Simple CSS CENTER DIV Example
* See Fiddle in link for PoC *
-->
<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>