• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

how to center a site without using the <center> element (depreciated)?

I would like my site to be centered when requested. So, regardless of the user's monitor size, the site is always in the center.

I tried using the HTML element <center>; it does work; but it breaks some part of the site.

Given the example below, what would you add to the CSS or HTML to display it in the center of the page?

<!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">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<style type="text/css">
#container { width: 750px; }
#navigation { width: 100%; height: 1em; float: left; }
#navigation li { display: inline; }
#navigation li a { padding: .25em 1em; float: left;}
#main { width: 500px; float: left; }
#subsection { width: 200px; float: right; }
<div id="container">
<ul id="navigation">
<li><a href="">Home</a></li>
<li><a href="">About</a></li>
<li><a href="">Stuff</a></li>
<div id="main">
<p>Duis aute irure dolor ullamco laboris nisi in reprehenderit in voluptate.
Ut labore et dolore magna aliqua. .</p>
<p>Sunt in culpa velit esse cillum dolore qui officia deserunt. Eu fugiat
pariatur. Excepteur sint occaecat lorem ipsum dolor sit amet, sunt in culpa.
Velit esse cillum dolore quis nostrud exercitation duis aute irure dolor.
Ut enim ad minim veniam, excepteur sint occaecat sunt in culpa.</p>
<p>In reprehenderit in voluptate. Quis nostrud exercitation ut labore
et dolore
magna aliqua. Excepteur sint occaecat lorem ipsum dolor sit amet, cupidatat
non proident. Qui officia deserunt quis nostrud exercitation velit esse cillum
dolore. In reprehenderit in voluptate ut aliquip ex ea commodo consequat.</p>
<div id="subsection">
<p>Omnis dolor repellendus. Et quasi architecto beatae vitae consectetur,

Open in new window

1 Solution
body align="center"
or css body { text-align:center; }
should work
several options using div tags:

Mark StegglesWeb DeveloperCommented:

The correct way is to use auto margins like so:

#container {
margin:0px auto;
width: 750px

epifanio67Author Commented:
the link gave me the clues.... got the answer... thx

margin: auto

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now