HTML Element Style How to - Center div








Question

We would like to know how to center div.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div {<!--   w  w  w. j  a va 2  s . c  o m-->
  border-radius: 5px;
}

#header {
  /*position: fixed;*/
  background-color: #3399ff;
  color: white;
  width: 60%;
  margin: auto;
}

#header p {
  display: inline;
}
</style>
</head>
<body>
  <div class="headerContainer">
    <div id="header">
      <p>This is a test.</p>
      <p>email</p>
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: