-2

using inline block and margin-left auto and margin-right auto the image doesnt center

G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129

2 Answers2

0

Image is center and responsive.

img {
  display: block;
  margin-left: auto;
  margin-right: auto;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>

</style>
</head>
<body>

<h2 style="text-align:center">This image is center and responsive</h2>


<img src="https://www.w3schools.com/howto/img_paris.jpg" alt="Paris" style="width:50%;">

</body>
</html>
Weyers de Lange
  • 280
  • 2
  • 11
-1

.container {
  width: 500px;
  border: 1px solid red;
  padding: 10px;
}

.container__img {
  /* TAKES PART OF THE DIV */
  width: 80%;

  heigh: 100%;
  margin: 0 auto;
}

img {
  width: 100%;
  heigh: 100%;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>

</style>
</head>
<body>
<div class="container">
  <div class="container__img">
    <img src="https://hatrabbits.com/wp-content/uploads/2017/01/random.jpg" alt="image">
  </div>
</div>


</body>
</html>
Weyers de Lange
  • 280
  • 2
  • 11
B.Ch.
  • 220
  • 1
  • 10