CSS Layout How to - Horizontally Centering Absolute Positioned Div








Question

We would like to know how to horizontally Centering Absolute Positioned Div.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#container {<!--  ww  w. jav  a2 s . c om-->
  width: 100%;
  margin: 0 auto;
  background: red;
  overflow: hidden;
}

#logo {
  height: 96px;
  width: 484px;
  margin: 50px auto;
  background: cyan;
}
</style>
</head>
<body>
  <div id="header">
    <div id="container">
      <div id="logo">
        <a href=""><img src="http://www.java2s.com/style/download.png" /></a>
      </div>
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: