Web Design Blog

This is where we store some of our Web Development thoughts, tips and tricks, just because we like to share.

Centering A Div With CSS

I get this question a lot, “How do you center a div?”

Central aligned websites are extremely common. Back in the day most websites were aligned to the left, but long gone are those days. Although, I do see the odd few keeping it old school (which is all very cool).

Centered Website

example of a centered div

Left aligned website

example of a left aligned div

There are a few methods of creating a centering div, but this is how I do it…

1
2
3
4
5
6
7
8
9
10
11
12
<html>
<head>
<title>
How to centre a div, by BrightCherry
</title>
</head>
<body>
<div id="wrapper">
	Hello world.
</div>
</body>
/html>
1
2
3
4
5
6
7
8
9
10
11
12
13
body {
	text-align:center;
	margin:0;
	padding:0;
}
 
 
#wrapper{
	margin: 0 auto;
	width:800px;
	text-align:left;
	background:#eee;
}

It’s as easy as that.

09 Aug 2008 / 0 Comments / CSS Tips & Tricks / by Maruf

Leave a Reply

© 2012 BrightCherry :)