javascript - Centering a div which has an image overlayed on top -
i have container div image overlayed on top of it.
i want center container div within basic popin. sure has overlay approach using within css, cannot figure out. how can center container dev within popin?
edit: there several of these blocks placed in-line.
css , html follows:
.containerdiv { float: left; position: relative; } .cornerimage { position: absolute; top: 0; left: 0; } .popin{ background:#fff; padding:15px; box-shadow: 0 0 20px #999; border-radius:2px; } #underlay1 { width: 320px; height: 320px; position: relative; } #underlay2 { width: 320px; height: 320px; position: relative; }
<div class="row"> <div class="col-md-4 col-sm-6 popin"> <div class="containerdiv"> <div id="underlay1"></div> <img class="cornerimage" border="0" src="http://lorempixel.com/320/320" alt=""> </div> </div> <div class="col-md-4 col-sm-6 popin"> <div class="containerdiv"> <div id="underlay2"></div> <img class="cornerimage" border="0" src="http://lorempixel.com/320/320" alt=""> </div> </div> </div>
underlay receiving image api. overlayimage.gif image being placed on top.
just remove float: left;
.containerdiv
, give text-align: center;
.popin
solve issue.
you can center absolute div following way:
left: 50%; transform: translate(-50%, 0px);
edit:
use margin: 0 auto;
#underlay
per expected output.
check fiddle
Comments
Post a Comment