KC Here KC Here - 1 year ago 64
CSS Question

When my div is not getting horizontally centered?

Why is the image not centered here?

#image {
margin: 0 auto;

<div id="image">
<img src="https://placekitten.com/200/300">

But it works perfect with a

My fiddle

Answer Source

Or you could just use flexbox

#image {
  height: 90vh;
  width: 90vw;
  display: flex;
  justify-content: center;
  align-items: center;

You don't need the 90vh or 90vw but you do need to give the height and width some value. Whether it's in px or % is up to you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download