How can I center my site

Posted on 2011-04-23
Medium Priority
Last Modified: 2012-05-11
Hello, I have a pretty basic knowledge of CSS and I'm trying to center this website:


I tried aplying text-align to the primary div but everything inside got centered.

Thanks in advance.
Question by:IvanGarcete
  • 2
LVL 13

Assisted Solution

jonahzona earned 1000 total points
ID: 35454271
If you want to center a div, you have to set margins.

For a div that is 800px wide, it would look like this.
#center {
  Width: 800px;
  Height: 100%;
  Margin: 0pt auto;

Open in new window

Obviously you can make it whatever height or width you want.
LVL 13

Expert Comment

ID: 35454277
Sorry about the capital letters in the syntax. They should be lower case. Typing on an iPad.
LVL 84

Accepted Solution

Dave Baldwin earned 1000 total points
ID: 35454290
I would use this.  984px looks like your widest element.
  width: 984px;
  margin-left: auto;
  margin-right: auto;

Open in new window


Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
Suggested Courses
Course of the Month17 days, 11 hours left to enroll

831 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