CSS Layout How to - Center images/paragraphs/buttons








Question

We would like to know how to center images/paragraphs/buttons.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#center {<!--from w  ww  .  j a  v  a 2 s.co m-->
  background-color: red;
  text-align: center;
}
</style>
</head>
<body>
  <div id="center">
    <button>button1</button>
  </div>
</body>
</html>

The code above is rendered as follows: