How to set table column width?

Discussion in 'PHP' started by globalcashsite, May 16, 2009.

  1. #1
    Guys

    I have 6 columns in one php table as follows:

    <<<<<< Table Heading >>>>>>>
    Col1 Col2 Col3 Col4 Col5 Col6

    Table heading will span and in center of all columns. And I don't want to that lower row columns adjust automatically. I want to adjust width of these lowe row columns myself. I tried many things but these are not working.

    Earlier table heading column was using "colspn=6" and I tried to set width of lower columns by using width="10" commands but that did not work.

    Then I removed "colspn" command from table heading column and lower column widths were decreased automatically. Then I tried to change width by width="10" command but that is not changing field width. Right now I am using these commands

    <TD bgcolor="blue" align="left" width=12>S.No</TD>
    <TD bgcolor="red" align="left" width=12>Tran Date</TD>
    <TD bgcolor="green" align="left" width=7>W.Days</TD>
    <TD bgcolor="navy" align="left" width=10>Invoice No</TD>
    <TD bgcolor="yellow" align="right" width=15>Amount</TD>
    <TD bgcolor="pink" align="left" width=50>Transaction Remarks</TD>

    But columns are not being adjusted according to above commands.

    Please help me how I can set column widths myself as I required.

    Thank you

    GCS
     
    globalcashsite, May 16, 2009 IP
  2. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #2
    Like this i guess

    <table border="1" width="500px">
    <tr>

    <TD bgcolor="blue" align="left" width=12>S.No</TD>
    <TD bgcolor="red" align="left" width=12>Tran Date</TD>
    <TD bgcolor="green" align="left" width=7>W.Days</TD>
    <TD bgcolor="navy" align="left" width=10>Invoice No</TD>
    <TD bgcolor="yellow" align="right" width=15>Amount</TD>
    <TD bgcolor="pink" align="left" width=50>Transaction Remarks</TD>
    </tr>
    </table>
     
    Bohra, May 16, 2009 IP
  3. alfa_375

    alfa_375 Active Member

    Messages:
    445
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #3
    This should definitely work.

    
    <table border="1" width="500px">
    <tr>
    
    <TD bgcolor="blue" align="left" width="12">S.No</TD>
    <TD bgcolor="red" align="left" width="100">Tran Date</TD>
    <TD bgcolor="green" align="left" width="7">W.Days</TD>
    <TD bgcolor="navy" align="left" width="70">Invoice No</TD>
    <TD bgcolor="yellow" align="right" width="15">Amount</TD>
    <TD bgcolor="pink" align="left" width="130">Transaction Remarks</TD>
    </tr>
    </table>
    
    Code (markup):
     
    alfa_375, May 16, 2009 IP
  4. globalcashsite

    globalcashsite Peon

    Messages:
    806
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Guys

    Problem is solved. Bohra's code gave me hint. In fact I was doing right thing but I was under estimating pixels. When I read "500px" in his code then I remembered that I am mixing up pixels with number of characters. I just increased width from "12" to "60" for first columns and so on and every thing got perfect. :)

    Thank you for helping me.

    GCS
     
    globalcashsite, May 16, 2009 IP
  5. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #5
    Great you got it fixed :D
     
    Bohra, May 16, 2009 IP