Struggling to center an inner element with a position: absolute
property inside of a position: relative
element? Take a look at this code snippet (https://jsfiddle.net/qL0c8cau/):
html,body,div {margin:0;padding:0;}
.one {
position: relative;
margin: 50px auto;
width: 200px;
height: 100px;
background: #900;
}
.two {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: auto;
background: #0f0;
opacity: 0.3;
height: 160px;
width: 400px;
}
<div class="one">
<div class="two"></div>
</div>
Frustrated because everything seems set up correctly, yet the alignment isn't quite right? What's the mistake in my approach?