TimString Posted October 5, 2012 Share Posted October 5, 2012 I have a simple php table of two columns. The left column is aligned right, and the second one is aligned left. For some reason or another, I can't post a screen shot. How do I get the space between those two columns aligned with the center of the page? Here's the code for the first row: echo "<table border = 0 width = 100%"; echo "<tr>"; echo "<td style='text-align:right; padding:3px 3px 0px 3px; Border:2px; font:15px Arial, sans-serif'>System:</td>"; //top right bottom left echo "<td style='text-align:left; padding:3px 3px 0px 3px; font:15px Arial, sans-serif'>" . $System . "</td>"; echo "</tr>"; Quote Link to comment https://forums.phpfreaks.com/topic/269130-centering-table-on-page/ Share on other sites More sharing options...
Jessica Posted October 5, 2012 Share Posted October 5, 2012 (edited) You can set each td to have a width of 50%. However if this is not tabular data, you should be using divs and CSS to format it. And fix your HTML. You never even closed the table tag, and you need to quote your attributes. Edited October 5, 2012 by Jessica Quote Link to comment https://forums.phpfreaks.com/topic/269130-centering-table-on-page/#findComment-1383004 Share on other sites More sharing options...
TimString Posted October 5, 2012 Author Share Posted October 5, 2012 Yes, it is tabular data generated by a PHP script and setting both columns to 50% didn't help. I did manage to get a screen shot posted thanks for the reply Quote Link to comment https://forums.phpfreaks.com/topic/269130-centering-table-on-page/#findComment-1383011 Share on other sites More sharing options...
Jessica Posted October 5, 2012 Share Posted October 5, 2012 Can you post a link please? Quote Link to comment https://forums.phpfreaks.com/topic/269130-centering-table-on-page/#findComment-1383012 Share on other sites More sharing options...
TimString Posted October 5, 2012 Author Share Posted October 5, 2012 http://bryanrails.zapto.org/rails/screenshot.gif Quote Link to comment https://forums.phpfreaks.com/topic/269130-centering-table-on-page/#findComment-1383014 Share on other sites More sharing options...
Jessica Posted October 5, 2012 Share Posted October 5, 2012 (edited) No, to the page. Or view the source and paste the HTML. Edited October 5, 2012 by Jessica Quote Link to comment https://forums.phpfreaks.com/topic/269130-centering-table-on-page/#findComment-1383017 Share on other sites More sharing options...
Barand Posted October 5, 2012 Share Posted October 5, 2012 Make both columns the same width. Specify "margin-left:auto; margin-right:auto" for the table object's style Quote Link to comment https://forums.phpfreaks.com/topic/269130-centering-table-on-page/#findComment-1383018 Share on other sites More sharing options...
TimString Posted October 5, 2012 Author Share Posted October 5, 2012 Barand, that didn't work, or I have misunderstood you. Here's a link to my site:http://bryanrails.zapto.org/rails use 41146 as the tech number and the password is "test" When you get to the Enter Display Channel, pull the drop-down menu to Bryan, TX and enter 69 in the top box. thanks for the help tim Quote Link to comment https://forums.phpfreaks.com/topic/269130-centering-table-on-page/#findComment-1383053 Share on other sites More sharing options...
Jessica Posted October 5, 2012 Share Posted October 5, 2012 (edited) <br /><table border = 0 width = 100%<tr><td style='text-align:right; padding:3px 3px 0px 3px; Border:2px; font:15px Arial, sans-serif'>System:</td><td style='text-align:left; padding:3px 3px 0px 3px; font:15px Arial, sans-serif'>Bryan, TX</td></tr><tr><td style='text-align:right; padding:3px 3px 0px 3px; Border:2px; font:15px Arial, sans-serif'>Display Channel:</td><td style='text-align:left; padding:3px 3px 0px 3px; font:15px Arial, sans-serif'>69</td></tr><tr><td style='text-align:right; padding:3px 3px 0px 3px; Border:2px; font:15px Arial, sans-serif'>Station:</td><td style='text-align:left; padding:3px 3px 0px 0px; font:15px Arial, sans-serif'>Inspirational (Digital Only)</td></tr><tr><td style='text-align:right; padding:3px 3px 0px 3px; font:15px Arial, sans-serif'>EIA Channel:</td><td style='text-align:left; padding:3px 3px 0px 0px; font:15px Arial, sans-serif'>75</td></tr><tr><td style='text-align:right; padding:3px 3px 0px 3px; font:15px Arial, sans-serif'>Frequency:</td><td style='text-align:left; padding:3px 3px 0px 0px; font:15px Arial, sans-serif'>531 MHz</td></tr></table><br /><table style='border-collapse:collapse; font:15px Arial, sans-serif'; width='100%' border='3'><CAPTION>Stations on Digital Rail 75</CAPTION><tr><th style='font-size:1em; font:15px Arial, sans-serif'; width = '80%'>Station</th><th style='font-size:.85em; font:15px Arial, sans-serif';width = '20%'> Display <br /> Channel</th></tr><tr bgcolor='#A9F5A9'><td style='text-align:left; padding:3px 0px 3px 12px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>Bravo</td><td style='text-align:right; padding:3px 12px 3px 0px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>63</td></tr><tr bgcolor='#FFFFFF'><td style='text-align:left; padding:3px 0px 3px 12px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>MSNBC</td><td style='text-align:right; padding:3px 12px 3px 0px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>64</td></tr><tr bgcolor='#A9F5A9'><td style='text-align:left; padding:3px 0px 3px 12px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>CMT</td><td style='text-align:right; padding:3px 12px 3px 0px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>65</td></tr><tr bgcolor='#FFFFFF'><td style='text-align:left; padding:3px 0px 3px 12px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>GAC</td><td style='text-align:right; padding:3px 12px 3px 0px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>66</td></tr><tr bgcolor='#A9F5A9'><td style='text-align:left; padding:3px 0px 3px 12px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>CSPAN2</td><td style='text-align:right; padding:3px 12px 3px 0px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>67</td></tr><tr bgcolor='#FFFFFF'><td style='text-align:left; padding:3px 0px 3px 12px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>TBN</td><td style='text-align:right; padding:3px 12px 3px 0px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>68</td></tr><tr bgcolor='#A9F5A9'><td style='text-align:left; padding:3px 0px 3px 12px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>Inspirational (Digital Only)</td><td style='text-align:right; padding:3px 12px 3px 0px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>69</td></tr><tr bgcolor='#FFFFFF'><td style='text-align:left; padding:3px 0px 3px 12px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>LMN</td><td style='text-align:right; padding:3px 12px 3px 0px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>70</td></tr><tr bgcolor='#A9F5A9'><td style='text-align:left; padding:3px 0px 3px 12px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>Jewelry (Digital Only)</td><td style='text-align:right; padding:3px 12px 3px 0px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>71</td></tr><tr bgcolor='#FFFFFF'><td style='text-align:left; padding:3px 0px 3px 12px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>EWTN (Digital Only)</td><td style='text-align:right; padding:3px 12px 3px 0px; border-collapse:collapse; font:15px Arial, sans-serif'; border = '3'>72</td></tr></table> <html> As I told you, your table tag is not closed, and you need to quote the attributes. You also did NOT add any 50%. Make the first two <td>s into <th> and put style="width: 50%" on them. Edited October 5, 2012 by Jessica Quote Link to comment https://forums.phpfreaks.com/topic/269130-centering-table-on-page/#findComment-1383054 Share on other sites More sharing options...
TimString Posted October 5, 2012 Author Share Posted October 5, 2012 yes, my table tag is closed. However, your suggestion worked. tyvm, tim Quote Link to comment https://forums.phpfreaks.com/topic/269130-centering-table-on-page/#findComment-1383056 Share on other sites More sharing options...
Jessica Posted October 5, 2012 Share Posted October 5, 2012 You think <table border = 0 width = 100%<tr> is valid code? Run it through a validator and see. Quote Link to comment https://forums.phpfreaks.com/topic/269130-centering-table-on-page/#findComment-1383057 Share on other sites More sharing options...
berridgeab Posted October 5, 2012 Share Posted October 5, 2012 I would also remove your login details from your post this is a public forum. Quote Link to comment https://forums.phpfreaks.com/topic/269130-centering-table-on-page/#findComment-1383065 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.