What is the difference between visibility:hidden and display:none?

前端 未结 18 1631
余生分开走
余生分开走 2020-11-21 04:50

The CSS rules visibility:hidden and display:none both result in the element not being visible. Are these synonyms?

18条回答
  •  清酒与你
    2020-11-21 05:15

    display: none; 
    

    It will not be available on the page and does not occupy any space.

    visibility: hidden; 
    

    it hides an element, but it will still take up the same space as before. The element will be hidden, but still, affect the layout.

    visibility: hidden preserve the space, whereas display: none doesn't preserve the space.

    Display None Example:https://www.w3schools.com/css/tryit.asp?filename=trycss_display_none

    Visibility Hidden Example : https://www.w3schools.com/cssref/tryit.asp?filename=trycss_visibility

提交回复
热议问题