CSS Layout How to - Create Centered paragraph








Question

We would like to know how to create Centered paragraph.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
p {<!--from  w ww  .jav a  2s  .c om-->
  background: grey;
  height: 200px;
  left: 50%;
  margin: -100px 0 0 -100px; /* half of the height and width */
  position: absolute;
  top: 50%;
  width: 200px;
}
</style>
</head>
<body>
  <p>center</p>
</body>
</html>

The code above is rendered as follows: