Solved

TD Width in CSS

Posted on 2013-11-26
4
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

749 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