/    Sign up×
Community /Pin to ProfileBookmark

Can’t center page in Firefox! Help!

I have been working on building a site for my father’s company and I decided to try out CSS. This is my first real attempt at creating a website and using CSS so it has been a learning experience!

I have the site setup here to test: [url]http://www.lifeatspeed.com/pax/[/url] . The CSS file is at [url]http://www.lifeatspeed.com/pax/Main.css[/url] .

The page loads the same in both IE6 and Firefox (haven’t tested others), but in Firefox the site is aligned to the left instead of in the center like in IE6. I have verifed all the pages as valid XHTML transitional on W3C and the CSS is valid as well. Can someone point me in the right direction on this one? It has to be something simple, but I’m at a loss.

to post a comment
CSS

6 Comments(s)

Copy linkTweet thisAlerts:
@BonRougeMay 20.2005 — Put div tags around the whole page and give it an id - say "container" or "wrapper" and then do this : #container {
position:relative;
margin:auto;
width:850px;
}

(or maybe 848px - I'm not really sure why you've set different widths for IE and Firefox - IE should work kind of OK as you have a good DTD).

Anyway, that should do it.
Copy linkTweet thisAlerts:
@gtvr4meauthorMay 20.2005 — Thanks for the info, I will try adding the wrapper when I get back home today. I have different widths because it was the only way I could have everything line up pixel for pixel in both FF and IE. Is there a way to have everything line up without having different widths?

I thought it was necessary because FF takes the border into consideration when displaying widths so the 848px for FF looks the same as the 850px for IE because there is a 1 pixel border on each side. If I left it 850 for both or 848 for both, one would look ok and the other would be slightly off.

It was so frustrating trying to get it all to linup because I didn't have much prior experience with CSS that I almost went back to tables for layout :eek: .
Copy linkTweet thisAlerts:
@FangMay 20.2005 — This is the basic centering of contents. To ensure the widths are the same across browsers use the [URL=http://www.w3.org/International/articles/serving-xhtml/#quirks]correct DTD[/URL].

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>center contents</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<style type="text/css">
<!--
body {text-align:center;}
#container {margin:0 auto; width:850px; text-align:left; border:1px solid red;}
-->
</style>

</head>
<body>
<div id="container">
<div id="contents">contents</div>
</div>
</body>
</html>
Copy linkTweet thisAlerts:
@gtvr4meauthorMay 20.2005 — After reviewing your DTD link, the fact that I have an XML declaration above the DTD could be the problem.

[CODE]<?xml version="1.0" encoding="iso-8859-1"?>[/CODE]

I use Dreamweaver MX and this code is automatically input, so I'll read more to see if this is the problem and how to fix it. From what I read it appears IE has issues when anything comes before the DTD.
Copy linkTweet thisAlerts:
@BonRougeMay 20.2005 — Yes!!! Don't trust Dreamweaver. That XML declaration throws it into quirks mode. I actually downloaded your page so that so that I could work on it, but I didn't see the XML declaration. I guess it got lost somewhere in the translation. Without that, I think you should be fine.

By the way - in case you'd considered it - never use any of DW's javascript - it's a bit on the crap side...
Copy linkTweet thisAlerts:
@gtvr4meauthorMay 21.2005 — Thanks for all the help, I got it to work now by using the container DIV. Funny thing is I already had a container coded in the html files called ParentDiv, but when I looked in my style sheet it wasn't there! I must have taken it out.
×

Success!

Help @gtvr4me 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...