CSS Layout How to - Center outer and inner div








Question

We would like to know how to center outer and inner div.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#box {<!--  w ww  .jav  a  2 s. c o m-->
  margin: auto;
  background: white;
  width: 100%;
}

.fake-pad {
  padding: 10px;
  border: 1px solid red;
}
</style>
</head>
<body>
  <div id="box" class="fake-pad">
    <div id="inner-fake-box" class="fake-pad">
       asdf
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: