Search code examples
csshtmlcentertext-align

HTML CSS Image won't center


I have problem : my picture doesn't want to center despite I used text-aligne:center;, display:block; and margin: 0 auto;

Here is a picture

http://imgur.com/a/jafpQ

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  background-attachment: fixed;
  background-size: 100%;
}

#container {
  max-width: 1000px;
  margin: 0 auto;
}

#Logo {
  text-align: center;
}
<!DOCTYPE HTML>
<html lang="pl">

<head>
  <meta charset="utf-8" />
  <title>str</title>
  <meta name="description" content=" bbbbbbb" />
  <meta name="keywords" content="bablal" />
  <meta http-equiv="X-UA-COMPATIBLE" content="IE=edge.chrome=1" />
  <link rel="stylesheet" href="new.css" type="text/css" />
  <link href="https://fonts.googleapis.com/css?family=Oxygen:300,400&amp;subset=latin-ext" rel="stylesheet">
</head>

<body background="photo/ik.png">
  <div id="container">
    <div id="Logo">
      <img src="photo/lg.png" width="800" height="533.5">
    </div>
  </div>
</body>

</html>


Solution

  • One way to do it using Flexbox.

    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      background-attachment: fixed;
      background-size: 100%;
    }
    
    #container {
      background: yellow;
      height: 100vh;
      width: 100vw;
      margin: 0 auto;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    <div id="container">
      <div id="Logo">
        <img src="http://placehold.it/200x100/333333">
      </div>
    </div>