Solved

center align website using css

Posted on 2010-09-17
4
259 Views
Last Modified: 2012-05-10
I am having problems centering my website, i want to do it in CSS so it changes all the pages.

I used the following code below in my css, and upon saving i saw it take effect in dreamweaver and the page centered but on the browser it's still left aligned.
BODY {
	FONT-FAMILY: Tahoma, Arial, Verdana, sans-serif;
	FONT-SIZE: 11px;
	COLOR: #3B3B3B;
	background-image: url(i/tile.gif);
	margin-left: auto;
	margin-right: auto;
	text-align: center;
}

Open in new window

0
Comment
Question by:newmie22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 33704114
This is what I normally do and it's used on a lot of web sites.  Since the <body> is the whole screen, you can't use it to center your content in CSS.  Instead, most people add a 'wrapper' DIV around their entire content inside the body like below.  The fixed width and auto margins center that div inside the body.
body {
  margin: 0;
  color:#000000;
  background-color: #ffffff;
  }

#wrap {
  position:relative;
  width: 960px; 
  margin-left: auto; 
  margin-right: auto;
  } 

Open in new window

0
 

Author Comment

by:newmie22
ID: 33704145
Thanks for the advice.  When i try that the page now goes back to being left aligned in dreamweaver and is still left aligned in the browser
0
 

Author Closing Comment

by:newmie22
ID: 33704261
Nevermind, this worked! Forgive my stupidity i left off the ending div to wrap the site! Thank you.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 33704561
You're welcome!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question