Solved

TD Width in CSS

Posted on 2013-11-26
4
307 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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. …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

728 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