Solved

center align website using css

Posted on 2010-09-17
4
242 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
  • 2
  • 2
4 Comments
 
LVL 82

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 82

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now