- The
visibility
CSS property shows or hides an element without changing the layout of a document -
The property can also hide rows or columns in a
table
visibility
CSS property shows or hides an element without changing
the
layout of a documenttable
visible
hidden
visibility set to visible
collapse
collapse
keyword has different effects for different elements:
table
rows
colums
column groups
row groups
display: none
row
or
column
from a table without forcing
the recalculation of widths and heights for the entire table
flex
items and ruby annotations are hidden, and the space
they would have
occupied is removed
collapse
is treated the same as
hidden
(i.e., the same
as visibility:hidden
, which works with (for example) a
div
tag)
.mydiv { visibility: hidden; }
<div>above</div> <div class="mydiv">Hello World</div> <div>below</div>
.mydiv2 { display: none; }
<div>above</div> <div class="mydiv2">Hello World</div> <div>below</div>
col {visibility: collapse}
h1 | h2 | h3 |
---|---|---|
d1 | d2 | d3 |
d1 | d2 | d3 |
h1 | h2 | h3 |
---|---|---|
d1 | d2 | d3 |
d1 | d2 | d3 |
.tvisible col { background-color: lightgoldenrodyellow; visibility: visible; } .tcollapse col { background-color: lightgoldenrodyellow; visibility: collapse; }
<table class="tvisible"> <caption>visibility:visible</caption> <colgroup> <col> </colgroup> <tr> <th>h1 </th> <th>h2</th> <th>h3</th> </tr> <tr> <td>d1</td> <td>d2</td> <td>d3</td> </tr> <tr> <td>d1</td> <td>d2</td> <td>d3</td> </tr> </table> <table class="tcollapse"> <caption>visibility:collapse</caption> <colgroup> <col> </colgroup> <tr> <th>h1 </th> <th>h2</th> <th>h3</th> </tr> <tr> <td>d1</td> <td>d2</td> <td>d3</td> </tr> <tr> <td>d1</td> <td>d2</td> <td>d3</td> </tr> </table>