2

In this question and answer we uncovered an interesting difference between Blink and Firefox/IE. What part of the spec concerns this issue and who is doing it correctly?

Suppose you have a table with 1 column and 2 rows. Row 1 has a bunch of inline text, and row 2 has a fixed width block.

  <table>
    <tr>
      <td>
        blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
      </td>
    </tr>
    <tr>
      <td>
        <div class="fixed-width"></div>        
      </td>
    </tr>
  </table>

with

.fixed-width {
  background-color: salmon;
  height: 200px;
  width: 200px;
}

table {
  width:0;
}  

Jsbin demonstrating this.

Chrome and Opera will ignore the width: 0 and expand to 100%

Chrome ignores width setting

Firefox and IE 11 will collapse the table to be as small width as possible.

IE 11 tries its best to apply it

Is this a case of Blink/webkit or IE/FF missing the spec? Is this behavior unspecified?

Community
  • 1
  • 1
George Mauer
  • 117,483
  • 131
  • 382
  • 612
  • Setting `display: block;` for `table` fixes the bug in Chrome. – Milan and Friends Jan 25 '14 at 23:40
  • Just a hunch, I have not had much sleep so just take this at face value, but the shrink-to-fit algorithm (which is according to the CSS 2.1 spec implementation defined) comes into play with [inline-block non-replaced elements](http://www.w3.org/TR/CSS2/visudet.html#inlineblock-width), which I think table cells qualify as in the spec. So I would guess "behavior is unspecified." – bishop Jan 26 '14 at 00:00
  • not very usefull, but if is in a container with a 0 width, it behaves somehow like it should . http://jsbin.com/UhOQEzOz/1/edit (display +div ) , http://jsbin.com/UlOhEGI/1/edit (table) – G-Cyrillus Jan 26 '14 at 01:51

1 Answers1

1

Table specifications says If the width attribute is not set, a table takes up the space it needs to display the table data. Simply webkit calculates it needs 100% available width to display long text inside the cells (noone says it should take minimum width - that way cell height would increase). Since your table width cannot be applied than it is not considered. In the example above, if you use:

table {
    width: 300px;
} 

than it will be applied. In case you do not want to set table width, but want to keep it as small as it can be, than apply style to table-cell instead:

table td {
    width: 1px;
}

This will look good in all the browsers except IE7.

skobaljic
  • 9,379
  • 1
  • 25
  • 51
  • Which table specification? – BoltClock Feb 11 '14 at 14:42
  • Except that the table width **is** set - it is set to 0. Fair point about applying the style to the `td` instead [this works in chrome](http://jsbin.com/UVAnUqEr/11/). Can you link to the table specification that you're siting? I'm still not sure which behavior is correct or is it unspecified? – George Mauer Feb 11 '14 at 15:49
  • You can find table definitiion and usage here: http://www.w3schools.com/tags/att_table_width.asp The width of zero cannot be applied to table - it is not a block element and it will auto-expand to `take up the space it needs to display the table data` – skobaljic Feb 12 '14 at 10:09