Horizontal center dynamic image in div with absolute position

北城余情 提交于 2019-11-30 06:53:41

If you want it to be absolute position do it like this:

http://jsbin.com/aveped/1/edit

img {
  width:20%;
  display:block;
  position:absolute;
  left:0;
  right:0;
  bottom:0;
  margin:auto;
}

The parent needs to have position relative, or it will be positioned against the body. You dont need width for this, I just included width because my image is so big.

left = center position - half the width of the image

img {
   position: absolute;
   bottom: 0;
   left: 50%; /*half the container width*/
   margin-left: -250px; /*half the width of the image*/
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!