Centering A Div With CSS

Image frame
Centering A Div With CSS
Maruf
Aug 9th, 2008
Maruf scribbled this post.

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.


Filed away: CSS

feel free to leave a scribble

Name:
Email:
gravatar
Want an image next to your comments?
visit gravatar.com
Message:
Get a free quote