css div position center code example
Example 1: center a div in css
.container {
display: flex;
justify-content: center;
align-items: center;
}
Example 2: center a div css
.center {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Example 3: 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 4: css center position
body {
text-align: center;
}
tag_name {
display: inline;
}
tag_name {
display: block;
width: 170px;
}
tag_name {
display: block;
width: 100px;
margin: 0 auto 0 auto;
}
Example 5: how to center align the html element in css examples
#inner {
width: 50%;
margin: 0 auto;
}
# center text
.center {
text-align: center;
border: 3px solid green;
}