I am trying to center absolute items inside my .child_div
element with a green background. How can I do this properly?
.parent_div {
position: relative;
background: lightgreen;
width: 1200px;
margin: auto;
}
.child_div {
position: relative;
height: 200px;
margin: auto;
display: flex;
justify-content: center;
}
.item {
width: 80px;
height: 80px;
position: absolute;
}
.item1 {
background: orange;
left: 20%;
}
.item2 {
background: yellow;
left: 25%;
}
.item3 {
background: blue;
left: 30%;
}
.item4 {
background: red;
left: 35%;
}
<div class="parent_div">
<div class="child_div">
<div class="item item1"></div>
<div class="item item2"></div>
<div class="item item3"></div>
<div class="item item4"></div>
</div>
</div>