Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

TD Width in CSS

Is it possible to set the width of a col of a table?

For example I currently have:-
<style>
     .col1 { width: 20px; }
     .col2 { width: 30px; }
     .col3 { width: 40px; }
     .col4 { width: 50px; }
</style>

<table>
     <tr>
          <td class="col1">1</td>
          <td class="col2">1</td>
          <td class="col3">1</td>
          <td class="col4">1</td>
     </tr>
     <tr>
          <td class="col1">2</td>
          <td class="col2">2</td>
          <td class="col3">2</td>
          <td class="col4">2</td>
     </tr>
     <tr>
          <td class="col1">3</td>
          <td class="col2">3</td>
          <td class="col3">3</td>
          <td class="col4">3</td>
     </tr>
</table>

Open in new window


Currently it just seems to ignore the CSS width

I know I can set the TD width as below, but would prefer to set it in CSS:-
<td width="40px">3</td>

Open in new window

0
tonelm54
Asked:
tonelm54
  • 2
  • 2
1 Solution
 
GaryCommented:
The code works fine - what makes you think it is ignoring your css?
http://jsfiddle.net/ff6tj/

But tables will mess up your css if it needs to arrange cells to better fit the content.
0
 
tonelm54Author Commented:
Ok, really strange, that code is working, but when I put it in my site it doenst:-
Test
0
 
GaryCommented:
All those TD's have a width set to 50px exactly as it is set in the CSS
0
 
tonelm54Author Commented:
Doh, the problem was with the table width="100%"
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now