Connecting Tech Pros Worldwide Forums | Help | Site Map

Table wont Centre in FF 3?

Familiar Sight
 
Join Date: Sep 2008
Posts: 255
#1: Jan 27 '09
I have the below code, now the text outside of the table will centre fine in IE and FF but the table will not centre at all in FF but is fine in IE??

Expand|Select|Wrap|Line Numbers
  1. <div id="search_body_wrapper">
  2.     <div id="search_body_results">
  3.         <b>3</b> result(s) found for <b>test</b>.<br /><br />
  4.         <table border="0" cellspacing="2" cellpadding="2">
  5.             <tr style="background-color: #CCCCCC;"><td style="font-weight: bold;">Case Number</td><td style="font-weight: bold;">Summary</td></tr>
  6.             <tr style="background-color: #DEDEDE;"><td>1000001</td><td>Test Case 1</td></tr>
  7.             <tr style="background-color: #DEDEDE;"><td>1000002</td><td>Test Case 2</td></tr>
  8.             <tr style="background-color: #DEDEDE;"><td>1000013</td><td>Test Case, Entered via web form</td></tr>
  9.         </table>
  10.     </div>
  11. </div>
Expand|Select|Wrap|Line Numbers
  1. #search_body_wrapper {
  2.     float: left;
  3.     width: 800px;
  4.     margin: 5px 5px 0 5px;
  5.     padding: 0 0 5px 0;
  6.     background-color: #FFFFFF;
  7.     text-align: left;
  8.     clear: left;
  9.     display: inline;
  10. }
  11. #search_body_results {
  12.     float: left;
  13.     width: 100%;
  14.     margin: 5px 0 0 0;
  15.     text-align: center;
  16.     clear: left;
  17.     display: inline;
  18. }

drhowarddrfine's Avatar
Expert
 
Join Date: Sep 2006
Posts: 5,580
#2: Jan 28 '09

re: Table wont Centre in FF 3?


Well, you're floating it left, so it's supposed to be on the left side. Why would it be different?

I don't have IE available so I haven't a clue why IE is doing it wrong and centering it but I'd bet all the modern browsers don't center it either.

Anyway, to center the table, put this in your CSS:
Expand|Select|Wrap|Line Numbers
  1. table{
  2. margin:0 auto
  3. }
  4.  
and never, ever look at IE as a reference for how things should work.
Newbie
 
Join Date: Aug 2007
Posts: 14
#3: Feb 5 '09

re: Table wont Centre in FF 3?


IE is possibly doing it wrong because there's no doctype, or an incomplete doctype, or some text or something before the doctype. IE in Quirks Mode will let text-align center blocks like tables when it shouldn't.

If the margin: 0 auto thing doesn't work at first, make sure that

the thing you want to center has a width
and
that width isn't 100% (you can't center something that's 100% wide)
Reply