SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Specifying cell widths - CSS or inline?

    How does one specify the width of a table cell (<td>)? Is it possible to do it inline? If so how?

    Neither way seems perfect to me since it involves lots of typing *shrug*

  2. #2
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, try this:
    Code:
    <html>
      <head>
        <style type="text/css">
        <!-- 
          td    {width: 100;
                 background-color: red;}
          td.w2 {width: 200;
                 background-color: green;}
          td.w3 {width: 300;  
                 background-color: blue;}
        -->
        </style>
      </head>
      <body>
        <table>
          <tr>
            <td>
              &nbsp;
            </td>
            <td class="w2">
              &nbsp;
            </td>
            <td class="w3">
              &nbsp;
            </td>
          </tr>
        </table>
      </body>
    </html>
    I actually typed &-nbsp; (no hyphen) in between the open and close <TD>s but SPF interpretted them when displaying.

    Above code only tested in IE6


    Andy
    From the English nation to a US location.

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2001
    Location
    North Wales, UK
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm pretty sure you need the units when specifying widths - presumably you mean pixels, so it should be:

    Code:
    width: 100px;

  4. #4
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The numbers default to pixels in IE however I don't know if that's the case in all browsers so you are correct that to be accurate the px should be included.


    Thanks,

    Andy
    From the English nation to a US location.

  5. #5
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    You can also use
    Code:
    <td style='width: 100px;'>
    as the style attribute accepts CSS styles.

  6. #6
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK thanks guys!

    Only that last one
    Code:
    <td style='width: 100px;'>
    seems a little unnecessary when
    Code:
    <td width="100px">
    would have accomplished the same in less typing. *shrug*


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •