/    Sign up×
Community /Pin to ProfileBookmark

centering with css

i want to center a div in css. not center the text, center the whole thing. basically i want to make a page with a fixed width, but its centered. i think you like set margins and then make its position relative or something. anyhu, i know it can be done, how?

to post a comment
CSS

3 Comments(s)

Copy linkTweet thisAlerts:
@IncaWarriorJul 08.2005 — margin: 0 auto;

width:xx;

margin centers it, but you need to set a width or it just spreads out and you won't see it centered
Copy linkTweet thisAlerts:
@gameguy43authorJul 08.2005 — does work. tried doing that to the body, and tried adding a main wrapper div and adding that, and niether worked. missing something?

edit. i screwed around with it, found something that worked. thanks.
Copy linkTweet thisAlerts:
@bathurst_guyJul 08.2005 — Just so everyone knows:

body {

text-align: center;

margin: 0;

padding: 0;

}

#wrapper {

margin: 0 auto;

width: 720px;

text-align: left;

}

<body>

<div id="wrapper>

<p>...</p>

</div>

</body>
×

Success!

Help @gameguy43 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...