Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1826 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     HTML/XHTML/DHTML/CSS :

Browserssssssss

Thread title: Browserssssssss
Closed Thread    
    Thread tools Search this thread Display Modes  
02-02-2008, 12:09 PM
#1
JamieH is offline JamieH
JamieH's Avatar
Status: I love this place
Join date: Jan 2006
Location:
Expertise:
Software:
 
Posts: 533
iTrader: 10 / 100%
 

JamieH is on a distinguished road

  Old  Browserssssssss

Hey,

I use to try and code quite a lot a while back but kept giving up because it wouldn't look right in either FF or IE... i know there is a load of other browsers too so how would i test the coding in all those browsers if i don't have them?

What sort of code would it be to align a box dead bang centre of the browser.. in all browsers?

Can someone write a little code for me to understand please?

+rep if u can thanks very much,
Jamie

02-02-2008, 01:36 PM
#2
Szandor is offline Szandor
Status: Junior Member
Join date: Jan 2008
Location: Växjö, Sweden
Expertise:
Software:
 
Posts: 45
iTrader: 0 / 0%
 

Szandor is on a distinguished road

  Old

I would say you just have to get all those browsers. All the browsers that count are free anyway. Most of them have their own quirks so there is no one that can replace them all when previewing.

Internet Explorer - Is quirky as hell, but it's the most common family of browsers.
Firefox - Has few quirks in the rendering, but they do exist.
Opera - The latest version actually renders correctly and does it fast too.
Safari - Is not very quirky, but suffers from using bolder characters that can mess up menus and such. There's a Windows version as well.
Lynx - A text browser that doesn't use CSS at all, good for checking your site for blind people. Also, it renders about the same as search engines render your site, so it's good for SEO.

I always design in Firefox since there are some kick ass add-ons I use all the time, then I check the site in the other browsers from time to time. I also use the "Total Validator" plugin in Firefox which lets me get screenshots of my site in various browsers on various systems.

As for the centering, I always use the following way:

Code:
#box {
	position: relative;
	width: 500px;
	left: 50%;
	margin-left: -250px; }
position: relative;
This lets me position the element. I can use other values as well, but the "position" attribute needs to be present in order to use the "left" attribute later on.

width: 500px;
Also needed for use later on. This method can't be used on relative widths, there are other ways for that. Make sure the width is an even number for perfect placement. (Odd numbers work too, but then your box will lean one pixel to right or left.)

left: 50%;
This places the left side of the element smack in the center of the screen. If I resize the viewport it will adjust itself.

margin-left: -250px;
Now we just pull back the box to place it in the center. The number should always be half of the width.

This method works in all major browsers with the only drawback being that if the viewport is made smaller than the box the scrollbar won't extend to make the left part visible, but it's a minor problem.

02-03-2008, 05:35 PM
#3
JamieH is offline JamieH
JamieH's Avatar
Status: I love this place
Join date: Jan 2006
Location:
Expertise:
Software:
 
Posts: 533
iTrader: 10 / 100%
 

JamieH is on a distinguished road

  Old

Thanks very much for the great reply.

What if i wanted to move the main content holder down from the top of the screen correctly?

Thank you.
Jamie

02-12-2008, 03:56 AM
#4
Awesome is offline Awesome
Awesome's Avatar
Status: Pastafarian
Join date: May 2006
Location: Duct Taped to your Ceiling
Expertise:
Software:
 
Posts: 3,440
iTrader: 26 / 93%
 

Awesome is on a distinguished road

  Old

Originally Posted by Szandor View Post
I would say you just have to get all those browsers. All the browsers that count are free anyway. Most of them have their own quirks so there is no one that can replace them all when previewing.

Internet Explorer - Is quirky as hell, but it's the most common family of browsers.
Firefox - Has few quirks in the rendering, but they do exist.
Opera - The latest version actually renders correctly and does it fast too.
Safari - Is not very quirky, but suffers from using bolder characters that can mess up menus and such. There's a Windows version as well.
Lynx - A text browser that doesn't use CSS at all, good for checking your site for blind people. Also, it renders about the same as search engines render your site, so it's good for SEO.

I always design in Firefox since there are some kick ass add-ons I use all the time, then I check the site in the other browsers from time to time. I also use the "Total Validator" plugin in Firefox which lets me get screenshots of my site in various browsers on various systems.

As for the centering, I always use the following way:

Code:
#box {
	position: relative;
	width: 500px;
	left: 50%;
	margin-left: -250px; }
position: relative;
This lets me position the element. I can use other values as well, but the "position" attribute needs to be present in order to use the "left" attribute later on.

width: 500px;
Also needed for use later on. This method can't be used on relative widths, there are other ways for that. Make sure the width is an even number for perfect placement. (Odd numbers work too, but then your box will lean one pixel to right or left.)

left: 50%;
This places the left side of the element smack in the center of the screen. If I resize the viewport it will adjust itself.

margin-left: -250px;
Now we just pull back the box to place it in the center. The number should always be half of the width.

This method works in all major browsers with the only drawback being that if the viewport is made smaller than the box the scrollbar won't extend to make the left part visible, but it's a minor problem.

Well now, that's just ridiculous.

Set 'text-align: center;' on the body element, and then when you set your wrapper width 'add margin: auto;'.

02-12-2008, 12:49 PM
#5
Szandor is offline Szandor
Status: Junior Member
Join date: Jan 2008
Location: Växjö, Sweden
Expertise:
Software:
 
Posts: 45
iTrader: 0 / 0%
 

Szandor is on a distinguished road

  Old

Originally Posted by Awesome View Post
Well now, that's just ridiculous.

Set 'text-align: center;' on the body element, and then when you set your wrapper width 'add margin: auto;'.
It feels better to me to target the specific element, not having to reset the alignment of every element within the <body>. Also, the method I use allows for more detailed positioning. I can set a block element to be 123px to the right of the center if I wish, making it easy to position stuff without having to use any extra <div> blocks or messing with floats more than absolutely neccessary.

In short, "margin: auto;" will center your content ("text-align: center;" is needed for IE6 in quirks mode), but the method I use can do a bit more than that. It's mostly a question of preference, really.

02-12-2008, 02:45 PM
#6
Dr John is offline Dr John
Status: Junior Member
Join date: May 2005
Location:
Expertise:
Software:
 
Posts: 77
iTrader: 0 / 0%
 

Dr John is on a distinguished road

  Old

I'm with Awesome on this. Using your method, Szandor, you have to remember to reset the margin-left if you change the width. One day you WILL forget.
And the problem with a small viewport has already been admitted. So that's two problems. The method you give is suitable for centering things inside another div, but as Awesome says, centering the entire content that way is unnecessary.

02-12-2008, 04:40 PM
#7
RaZoR^ is offline RaZoR^
RaZoR^'s Avatar
Status: Member
Join date: Feb 2006
Location:
Expertise:
Software:
 
Posts: 191
iTrader: 1 / 100%
 

RaZoR^ is on a distinguished road

  Old


It feels better to me to target the specific element, not having to reset the alignment of every element within the <body>.
Code:
body{text-align:center;}
#container{margin:auto;width:80%;text-align:left;}
Well, that was hard.

02-14-2008, 04:28 PM
#8
Szandor is offline Szandor
Status: Junior Member
Join date: Jan 2008
Location: Växjö, Sweden
Expertise:
Software:
 
Posts: 45
iTrader: 0 / 0%
 

Szandor is on a distinguished road

  Old

Originally Posted by RaZoR^ View Post
Code:
body{text-align:center;}
#container{margin:auto;width:80%;text-align:left;}
Well, that was hard.
I didn't say it was hard, I said it felt wrong. I use auto margins too, but the other method has a few advantages I like. It's also more compatible, which means I can support IE5 without having to center everything in my body.

I'm not saying you're doing it wrong, I'm just saying it's a different way.

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed