center a box css code example
Example 1: center a div in css
.container {
display: flex;
justify-content: center;
align-items: center;
}
Example 2: mettre une image au milieu css
IMG.displayed {
display: block;
margin-left: auto;
margin-right: auto }
...
<IMG class="displayed" src="..." alt="...">
Example 3: how to put container in center of page
#container
{
width: 400px;
margin-left: auto;
margin-right: auto;
}
Example 4: how to center a div vertically and horizontally
.container{
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width:
height:
}
Example 5: how to center a div
.container {
...
display: flex;
justify-content: center;
}
Example 6: 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>