Solved

TD Width in CSS

Posted on 2013-11-26
4
301 Views
Last Modified: 2013-11-26
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
Comment
Question by:tonelm54
  • 2
  • 2
4 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39679178
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
 

Author Comment

by:tonelm54
ID: 39679207
Ok, really strange, that code is working, but when I put it in my site it doenst:-
Test
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39679220
All those TD's have a width set to 50px exactly as it is set in the CSS
0
 

Author Comment

by:tonelm54
ID: 39679241
Doh, the problem was with the table width="100%"
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now