轉載自新浪博客->最初的你,文章地址:http://blog.sina.com.cn/s/blog_51048da7010185io.html
visibility和display兩個屬性都有隱藏元素的功能,display:none和visibility:hidden的區別,簡單的總結一句話就是:visibility:hidden隱藏,但在瀏覽時保留位置;而display:none視爲不存在,且不加載!
實例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
</head>
<body>
<table>
<tr>
<td>
<table border="1">
<tr>
<td>第一行</td>
</tr>
<tr style="display:none">
<td>第二行</td>
</tr>
<tr>
<td>第三行</td>
</tr>
</table>
</td>
<td>
<table border="1">
<tr>
<td>第一行</td>
</tr>
<tr style="visibility:hidden">
<td>第二行</td>
</tr>
<tr>
<td>第三行</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>style="display:none"</td>
<td>style="visibility:hidden"</td>
</tr>
</table>
</body>
</html>
結果:
說明:
爲了更深入理解,推薦這篇文章,可參考:
2、跟着w3c標準來探討display:none;與visibility:hidden;的區別->此文章中提到渲染樹等系列,不懂的戳下面文章,可以幫助更好的理解: