align image in middle of div code example
Example 1: css center image
.center {
display: block;
margin-left: auto;
margin-right: auto;
}
Example 2: centre align image in div
body {
margin: 0;
}
#over img {
margin-left: auto;
margin-right: auto;
display: block;
}
Example 3: how to horizontal center a div in css
#inner {
width: 50%;
margin: 0 auto;
}
Example 4: 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>