how to center a container css code example
Example 1: center a div in css
.container {
display: flex;
justify-content: center;
align-items: center;
}
Example 2: how to center text in css
.class {
text-align: center;
}
Example 3: how to center anything inside your container
display: grid;
place-items: center;
height: 100vh;
Example 4: 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>
Example 5: how to center a div
margin:auto
Example 6: center a div
<div id="outer">
<div id="inner">Foo foo</div>
</div>
//css:, demo with border
<style>
#inner {
display: table;
margin: 0 auto;
border: 1px solid black;
}
#outer {
border: 1px solid red;
width:100%
}
</style>