html how to center an image to a parent element

Solutions on MaxInterview for html how to center an image to a parent element by the best coders in the world

showing results for - "html how to center an image to a parent element"
Daphné
15 Feb 2016
1<!DOCTYPE html>
2<html>
3  <head>
4    <title>Center an Image using text align center</title>
5    <style>
6      .img-container {
7        text-align: center;
8        display: block;
9      }
10    </style>
11  </head>
12  <body>
13    <span class="img-container"> <!-- Inline parent element -->
14      <img src="user.png" alt="">
15    </span>
16  </body>
17</html>
Lee
25 Jan 2018
1.element {
2    object-fit: fill || contain || cover || none || scale-down;
3}
Louis
18 Jan 2019
1<!DOCTYPE html>
2<html>
3  <head>
4    <title>Center an Image using text align center</title>
5    <style>
6      .img-container {
7        text-align: center;
8      }
9    </style>
10  </head>
11  <body>
12    <div class="img-container"> <!-- Block parent element -->
13      <img src="user.png" alt="John Doe">
14    </div>
15  </body>
16</html>