Solved

TD Width in CSS

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Title # Comments Views Activity
Problem to refer to value 8 62
HTML - Color not displaying correctly in EMAIL. 6 49
html input 8 42
Override MS CSS in SharePoint Online Modal Form 19 43
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

856 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