Margin: 0 auto is not centering my image

妖精的绣舞 提交于 2019-12-03 12:12:39

Put display: block; on it. By default, images are inline.

To center inline —default for image— or inline-block elements, just center it as text. This means, you will need to use text-algin on the parent element:

div#pictures {
  text-align: center;
}

The other solution is the one from @One Trick Pony, and display the image as a block element and just then apply the automatic margin.

#pictures img{
display:block;
}

Add this code then i will be centered

i know this is an old post, but wanted to share how i solved the same problem.

My image was inheriting a float:left from a parent class. By setting float:none I was able to make margin:0 auto and display: block work properly. Hope it may help someone in the future.

You have two options:

  1. Remove img from #pictures and then put the image inside that div.

  2. Add the #pictures to the image Tag in html (inline style).

You might remove the display tag in #pictures.

Good luck with that.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!