how to centre a div in html?

  • Thread starter Thread starter linkinhardyy
  • Start date Start date
L

linkinhardyy

Guest
I have tried this to centre a div but it doenst seem to work:

Code:
------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
div.someClass {
width: 100%;
margin-left: auto;
margin-right: auto;
}
<title>Untitled Document</title>
</head>

<body>
<div class="someClass"style="background-color:red;align:center;width:800px;">
  <h3 align="left">This is a header</h3>
  <p>This is a paragraph.</p>
</div>

</body>
</html>
--------

How do I centre a div?
 
Just add Align attribute in <div> tag as in following.

<div align="center">hello</div>

hello will be displayed in the center of the page.
 
Back
Top