How do I use the visibility property?
Author: Deron Eriksson
Description: This CSS tutorial describes the visibility property and also mentions how it compares to the display property set to none.
Tutorial created using:
Windows XP
The visibility property specifies whether an element's content is visible or not. Its values can be visible, hidden, collapse, and inherit. The default value is inherit. If visibility is set to visible, the element displays normally. If visibility is set to hidden, the element's content is hidden (but transparent), but the element still takes up the same location of its generated box. If visibility is set to collapse and the element is not a row or column, according to the CSS2 specification, collapse should have the same meaning as hidden. Firefox does this correctly, but IE6 and IE7 do not treat collapse as hidden. An important consideration is a comparison of visibility set to hidden and display set to none. If display is set to none, the element's box generation is prevented, so this removes this element from the page rendering. This is different from visibility set to hidden, in which the element content is simply made transparent, but the elements box generation still appears in the page rendering. The style-test.html file below shows several examples of setting the visibility property and the display property. style-test.html<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Style Test</title> <style type="text/css"> div { background-color: aqua; border: 1px solid;} </style> </head> <body> <h2>visibility property</h2> <div> <div style="visibility: visible;">This is visibility: visible;</div> <div style="visibility: hidden;">This is visibility: hidden;</div> <div style="visibility: inherit;">This is visibility: inherit;</div> <div style="visibility: collapse;">This is visibility: collapse;</div> </div> <h2>display property</h2> <div> <div style="display: none;">This is display: none;</div> <div style="display: block;">This is display: block;</div> </div> </body> </html> (Continued on page 2) |