[web] how to center div?

Started by
23 comments, last by ArchG 17 years, 10 months ago
in html, how do you tell your div to be centered at all resolutions?
-------------------------Only a fool claims himself an expert
Advertisement
you have to set the margin like this:

<div style="width:[width here]; margin: 0 auto;></div>

you can change the 0 to whatever you want. (Not really HTML but CSS is your friend [smile])
F-R-E-D F-R-E-D-B-U-R...G-E-R! - Yes!
<div align="center">blah


or

<div style="position:relative;left:25%;right:25%">blah2

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

cool, thanks.
-------------------------Only a fool claims himself an expert
Quote:Original post by capn_midnight
<div align="center">blah</div>
What browser are you using? When I do that in FireFox the div stays left-aligned and the text inside is centered.

F-R-E-D F-R-E-D-B-U-R...G-E-R! - Yes!
Quote:Original post by DigiDude
Quote:Original post by capn_midnight
<div align="center">blah</div>
What browser are you using? When I do that in FireFox the div stays left-aligned and the text inside is centered.


That's what it *should* do. The margin: auto is the correct way to do it, but IIRC Internet Explorer doen't like it (no surprise here...)

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

well after further use, the div now seems to be aligning itself to the left. using capn_midnights example. any more help?
edit: yeah, it behaves like DigiDude said. i'll try your example digidude.
-------------------------Only a fool claims himself an expert
i got it working, thanks for the help.
-------------------------Only a fool claims himself an expert
Many "Lounge Lizards" don't know there are other forums on GameDev, including the Web Development Forum [wink]. And yes, <div align="center">blah</div> it is.
Rob Loach [Website] [Projects] [Contact]
Quote:Original post by Rob Loach
And yes, <div align="center">blah</div> it is.

No no, that centers the content of the div.

- Jason Astle-Adams

This topic is closed to new replies.

Advertisement