0

I want to show an image in the center of a page with original size.

I tried the code below

.container 
    {
    
      margin-left: auto;
      margin-right: auto;
        vertical-align: middle;
     }
<html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
    
    
    <div class="container"><img src="1.png" alt="No Internet Connection" ></div>
    
    </body>
    </html>
xmaster
  • 1,042
  • 7
  • 20
Sabuj
  • 5
  • 5
  • 1
    Possible duplicate of [How to Vertical align elements in a div?](https://stackoverflow.com/questions/79461/how-to-vertical-align-elements-in-a-div) – Adriano May 28 '19 at 07:02

1 Answers1

1

.container 
    {
      display: flex;
    align-items: center;
    justify-content: center;
       height: 90vh;
     }
<html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
    
    
    <div class="container"><img src="1.png" alt="No Internet Connection" ></div>
    
    </body>
    </html>

You can use display: flex;. It's responsive and works great. After that I used justify-content: center; because of this it is horizontal in the center. And because of align-items: center; and height: 90vh; it is vertical centered

xmaster
  • 1,042
  • 7
  • 20