Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table attribute width is ignored

My goal is to generate a html file with tables and export them into pdf.
Unfortunately I cant get the table to act like I want.

One part of the table should display a timescale with days on the lowest row, weeks,months and years are in the rows above and have a pre-calculated colspan.

Only the s for the days have a width given with CSS (style="width:...").

The problem is that the width is totally ignored, so fields with days from 1-9 are only half as width than the others. And in follow, because the fields above size automatically because they have no width given, their size is also wrong.

alt text http://img217.imageshack.us/img217/6617/scale1x.jpg

Heres the source that is generated: http://pastebin.com/JyiqhSzs

What we tried so far:

  • used non css (width="")
  • give the other field also an calculated width (the colspan value multiplied with the width of a day)

Also set style="table-layout:fixed;" for the table but that has no effect.

So I don't know how to get the table to have the width I want to have?

like image 677
CSchulz Avatar asked Jul 22 '10 06:07

CSchulz


People also ask

How fix TD table width?

Using width attribute: The <td> tag has width attribute to control the width of a particular column. By assigning a numeric value to this attribute between 0 to 100 in terms of percentage(or you can use pixel format). We can restrict the column width up to that much percentage of the table's total width.

How do I make a table width in HTML?

To manipulate the height or width of an entire table, place the size attribute (either "WIDTH=" or "HEIGHT=") within the <TABLE> code. To manipulate individual cells, place the size attribute within the code for that cell.

How do you set column width in a table?

The width of the columns i.e. td in a table can be fixed very easily. This can be done by adding the width attribute in the <td> tag. If the width is not specified, the width of the column changes according to the change in the content. The specifications of width for the columns can be in pixels, or percentage.


2 Answers

Instead of width: 23px use min-width: 23px. It worked for IE8 and FireFox. I have not yet figured out a magic formula for IE7 to not narrow the single digit days (working on it). I do know that the table-layout: fixed is not needed, and for sure will cause issues with any IE7 display that may work.

Also, if you always want them to be the same size, you might consider using em sizing so that if text size changes, your table scales up/down with it proportionally. I don't know all your needs, but just a suggestion to look into.

Edit: More cross browser solution. IE6 and 7 need to have all the numbers in the "days" cells wrapped with a div and then instead of styling the td with any kind of width, style that div with a width: 23px not min-width: 23px.

like image 192
ScottS Avatar answered Sep 24 '22 04:09

ScottS


Is the style attribute mistyped as stlye in your real page, too?

Some more hints:

  • It's normal for table cell to shrink if the table doesn't fit on the whole page, that's how HTML tables work.
  • Try table-layout: fixed after fixing the typo.
  • If it still doesn't work you'll need to add a div (or some other element) to each cell and give that the width instead
  • A width in pixels won't work if the font isn't the size you expect (and no, you can't force it to a specific size). Try 2ex.
  • Instead of setting the style in each and every td why don't you set in the the style sheet.

Example:

<tr class="days"><td>1</td><td>2</td></tr>

tr.days td {
  width: 23px;
}
like image 20
RoToRa Avatar answered Sep 21 '22 04:09

RoToRa