6

Collapse

Only for table elements. collapse removes a row or column, but it does not affect the table layout. The space taken up by the row or column will be available for other content. If collapse is used on other elements, it renders as hidden.

http://www.w3schools.com/cssref/pr_class_visibility.asp

However, the element is still taking up space like visibility: hidden. I've tested on Safari and Chrome. Anyone have a solution where the table layout is maintained but the space is removed?

bfavaretto
  • 71,580
  • 16
  • 111
  • 150
Verdi Erel Ergün
  • 1,021
  • 2
  • 12
  • 20

2 Answers2

9

It won't work as intended on all browsers, only Firefox and IE (I can't confirm IE right now). The MDN docs on visibility say:

The support for visibility:collapse is missing or partially incorrect in some modern browsers. In many cases it may not be correctly treated like visibility:hidden on elements other than table rows and columns.

You can test it with this jsFiddle: http://jsfiddle.net/meT7k/. In Chrome, the first row is rendered as visibility: hidden. In Firefox, collapse is applied correctly.

In Chrome, you get the desired results when applying display: none to the row instead. However, that will probably force a re-layout of the whole table (e.g., column widths may change after the display property is changed).

bfavaretto
  • 71,580
  • 16
  • 111
  • 150
  • bfavaretto, seems like visibility:collapse isn't incorporated into browser support for webkit browsers. – Verdi Erel Ergün Oct 07 '12 at 15:34
  • Looks like that's it. FF supports it, and according to [msdn](http://msdn.microsoft.com/en-us/library/ie/ms531180(v=vs.85).aspx), ie8+ supports it too. – bfavaretto Oct 07 '12 at 15:59
  • It is a little late but you can get it to work in Chrome [this way](http://stackoverflow.com/questions/25807564/hiding-a-tr-while-still-involving-it-in-width-calculations/25807729#25807729) – Hashem Qolami Oct 04 '14 at 22:08
-1

Wrap the contents in a <span></span> and set the display to none.

Ryan
  • 288
  • 3
  • 11