CSS Layout How to - Center a div with margin auto








Question

We would like to know how to center a div with margin auto.

Answer


<!--from w  ww  .  j a v a2 s .  c  o  m-->
<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#page {
  width: 350px;
  height: 400px;
  border: 1px solid #000;
  margin: auto
}
</style>
</head>
<body>
  <div id="page"></div>
</body>
</html>

The code above is rendered as follows: