Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 5th, 2005, 03:35 AM
Jeff Thies
Guest
 
Posts: n/a
Default center align a page

I've got a page with content that I want aligned in the center, with
equal margins on both sides (text, left aligned).

It seems to me that this is a complex thing to get right on most
browsers and required putting the page in a div and then body:
textalign: center
and a few other hacks

There was a site that explained this rather well but I can't seem to
google it up. Where is that?

The page in question is fixed width and image heavy (photos) so it
escapes the normally very good reasons to not center align.

Cheers,
Jeff
  #2  
Old August 5th, 2005, 06:15 AM
Jim Moe
Guest
 
Posts: n/a
Default Re: center align a page

Jeff Thies wrote:[color=blue]
> I've got a page with content that I want aligned in the center, with
> equal margins on both sides (text, left aligned).
>[/color]
div.body { margin-left: auto; margin-right: auto; }
No hacks needed. Even works in IE6.

--
jmm dash list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
  #3  
Old August 5th, 2005, 07:35 AM
Spartanicus
Guest
 
Posts: n/a
Default Re: center align a page

Jeff Thies <jeff@spamalanadingong.com> wrote:
[color=blue]
> I've got a page with content that I want aligned in the center, with
>equal margins on both sides (text, left aligned).
>
> There was a site that explained this rather well but I can't seem to
>google it up. Where is that?[/color]

http://dorward.me.uk/www/centre/

Btw, David: you're a very naughty boy for using browser sniffing.
[color=blue]
> The page in question is fixed width and image heavy (photos) so it
>escapes the normally very good reasons to not center align.[/color]

It shouldn't be fixed width, thus there should be no point in centering
it.

--
Spartanicus
  #4  
Old August 5th, 2005, 08:25 AM
Els
Guest
 
Posts: n/a
Default Re: center align a page

Jim Moe wrote:
[color=blue]
> Jeff Thies wrote:[color=green]
>> I've got a page with content that I want aligned in the center, with
>> equal margins on both sides (text, left aligned).
>>[/color]
> div.body { margin-left: auto; margin-right: auto; }
> No hacks needed. Even works in IE6.[/color]

If you want it to work in WinIE5 too:
http://locusmeus.com/html-css/centeringpage.html

--
Els http://locusmeus.com/
Sonhos vem. Sonhos vão. O resto é imperfeito.
- Renato Russo -
  #5  
Old August 5th, 2005, 08:25 AM
David Dorward
Guest
 
Posts: n/a
Default Re: center align a page

Spartanicus wrote:
[color=blue]
> Btw, David: you're a very naughty boy for using browser sniffing.[/color]

I didn't write the script, and when I started using it my JS-foo wasn't good
enough to recognise the problem. I'll probably rewrite it one day.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
  #6  
Old August 5th, 2005, 08:25 AM
Spartanicus
Guest
 
Posts: n/a
Default Re: center align a page

David Dorward <dorward@yahoo.com> wrote:
[color=blue][color=green]
>> Btw, David: you're a very naughty boy for using browser sniffing.[/color]
>
>I didn't write the script, and when I started using it my JS-foo wasn't good
>enough to recognise the problem. I'll probably rewrite it one day.[/color]

Server side JS? (I have client side JS disabled)

But the problem isn't the accuracy since browser sniffing is inaccurate
by definition.

--
Spartanicus
  #7  
Old August 5th, 2005, 08:45 AM
David Dorward
Guest
 
Posts: n/a
Default Re: center align a page

Spartanicus wrote:
[color=blue][color=green][color=darkred]
>>> Btw, David: you're a very naughty boy for using browser sniffing.[/color][/color][/color]
[color=blue][color=green]
>>I didn't write the script, and when I started using it my JS-foo wasn't
>>good enough to recognise the problem. I'll probably rewrite it one day.[/color][/color]
[color=blue]
> Server side JS? (I have client side JS disabled)[/color]

No. Client-side JS. Its a hack to fake support for <abbr> in MSIE.
[color=blue]
> But the problem isn't the accuracy since browser sniffing is inaccurate
> by definition.[/color]

Rewrite it so that it does object detection (or uses conditional comments).

I think perhaps we are talking at crosspurposes here. What browser sniffing
do you think I use?


--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
  #8  
Old August 5th, 2005, 09:25 AM
Spartanicus
Guest
 
Posts: n/a
Default Re: center align a page

David Dorward <dorward@yahoo.com> wrote:
[color=blue]
>I think perhaps we are talking at crosspurposes here. What browser sniffing
>do you think I use?[/color]

Apologies, I thought you were using server side http UA header sniffing
to conditionally serve or deny CSS. I got unstyled content with my
standard setup, this is usually down to my spoofed UA header, but on
closer inspection one of my web page filters is doing unexpected things.

Off to check my filters.

--
Spartanicus
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles