Margin: 0 auto is not centering my image

后端 未结 5 1305
庸人自扰
庸人自扰 2021-02-14 12:25

I\'m very new to all of this and am trying to build this website, but the main image on the page is not centering. I\'ve tried all sorts of centering things but they don\'t work

相关标签:
5条回答
  • 2021-02-14 12:55

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

    0 讨论(0)
  • 2021-02-14 13:02

    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.

    0 讨论(0)
  • 2021-02-14 13:04
    #pictures img{
    display:block;
    }
    

    Add this code then i will be centered

    0 讨论(0)
  • 2021-02-14 13:14

    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.

    0 讨论(0)
  • 2021-02-14 13:16

    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.

    0 讨论(0)
提交回复
热议问题