#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2008
    Posts
    670
    Rep Power
    38

    <td width> not working


    Hi, when I use javascript (say jQuery, or Scriptaculous, or Prototype) on my web page my Table formatting does not work.
    For example, I would have
    Code:
    <td width="40">
    But the width property doesn't work.

    Does anyone know why this happens, and what the work around is? I know I could use CSS, but it's basically data in a table, and needs the <td>'s need to be a specific width.

    thanks!
    -
    Last edited by lelales; October 25th, 2012 at 08:52 AM. Reason: typo
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Location
    Stockholm, Sweden
    Posts
    16
    Rep Power
    0
    Originally Posted by lelales
    Hi, when I use javascript (say jQuery, or Scriptaculous, or Prototype) on my web page my Table formatting does not work.
    For example, I would have
    Code:
    <td width="40">
    But the width property doesn't work.

    Does anyone know why this happens, and what the work around is? I know I could use CSS, but it's basically data in a table, and needs the <td>'s need to be a specific width.

    thanks!
    -
    Hi lelales,

    To get a <td> element to hold it's given width you will need to specify the width attribute to 100% for the <table> element.

    Code:
    <table width="100%">
    <tr>
    <td width="40"></td>
    </tr>
    </table>
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    18
    Rep Power
    0
    You can use the following code

    <td style="width:40px;">

    Then let me know with the result.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2008
    Posts
    670
    Rep Power
    38

    Thanks hHeatleakz


    I'll give a try later today.
    Thanks so much!
    Last edited by lelales; October 26th, 2012 at 08:57 AM. Reason: typo
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Location
    Buenos Aires, Argentina
    Posts
    64
    Rep Power
    2
    Also, if you want to use relative values you can use:

    <td style="width:40%;">

    If you want a more accurate number:

    <td style="width:40.5%;">

    You may use the number you want and decimals. See ya.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    48
    Rep Power
    3
    Originally Posted by Heatleakz
    Hi lelales,

    To get a <td> element to hold it's given width you will need to specify the width attribute to 100% for the <table> element.

    Code:
    <table width="100%">
    <tr>
    <td width="40"></td>
    </tr>
    </table>

    Ummm...that's not true.

    The following would work fine:
    Code:
    <table width="300">
        <tr>
            <td width="60">
                Foo
            </td>
            <td>
                Bar
            </td>
        </tr>
    </table>
    You just need to keep in mind a couple of simple rules.

    1. Your specified td widths will not work if the sum of them all is less than (or greater than) than the specified width of the table. For example, if in the above example I told both of the TDs to be 20 pixels wide, then told the table to be 300 pixels wide--that would not add up, so it not display your specified TD widths. The standard work around for this is to have at least one TD with no specified width at all. This will cause all of the TDs with specified widths to work, and the extra will be shoved into the TD without a specified width.

    2. You should style your tables with CSS.
    Rather than using inline attributes for your TD widths, you should do it like this:
    Code:
     
    <table style="width: 300px;">
        <tr>
            <td style="width: 60px;">
                Foo
            </td>
            <td>
                Bar
            </td>
        </tr>
    </table>
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    31
    Rep Power
    0
    Width is a horrid and bogus tag, not recognised by xhtml.

    Learn CSS2

    Regards

IMN logo majestic logo threadwatch logo seochat tools logo