0

i'm using wordpress and i would like to center an image of the top of my post. I tried many way but nothing work. So here is the code :

<div class="entry-thumb">
            <img width="183" height="260" src="http://localhost/bdtresor/wp-content/uploads/gmb1_mister.president.2.JPG" class="attachment-newsanchor-large-thumb size-newsanchor-large-thumb wp-post-image" alt="Image du post 222">
</div>

the css

.entry-thumb {
    max-width: 1000px;
    /*margin: auto;*/
}

.entry-thumb {
  border : 1px solid black ; 
  }

img {
    max-width: 100%;
    height: auto;*/
    margin-left: auto;
    margin-right: auto;
}

I don't know how to do.When i pit a margin-left : 50px , it works but it's not centered , but if i put margin-left : auto , nothing happened... Thank you for you're help

GillesC
  • 10,647
  • 3
  • 40
  • 55
Flushdrew
  • 133
  • 1
  • 10

1 Answers1

1

Make the image display:block so that the margin centering works.

.entry-thumb {
    max-width: 1000px;
    /*margin: auto;*/
}

.entry-thumb {
  border : 1px solid black ; 
  }

img {
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    display:block;
}
<div class="entry-thumb">
            <img width="183" height="260" src="http://lorempixel.com/183/260" class="attachment-newsanchor-large-thumb size-newsanchor-large-thumb wp-post-image" alt="Image du post 222">
</div>

Keep in mind though that the max-width will conflict with the image dimensions since they are defined on the image. (you should remove the width and height attributes from the img tag)

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317