【CSS FAQ】 visibility: hidden; 與 display: none; 差在哪裡?

CSS FAQ 系列文開始囉!
這個系列會解答常見的 CSS 疑惑
如果還有想要知道什麼的話
都可以底下留言唷~
第一彈就是:visibility: hidden; 和 display: none; 的差別

See the Pen SP-Visibility / Display by Candy (@stringpiggy) on CodePen.22914


從上面的範例就可以明顯看出,display: none; 會讓元素連位置都消失。
而如果有使用 jQuery 中的 .hide() / .show(); 則是去調整 display 屬性。
總之,「大部分」的時候都是使用 display 這個屬性,至於什麼時候該用哪個就看你想要讓網頁看起來長什麼樣子囉!

Share
  • Copied the URL !

Comments

To comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Table of Contents