14. Visibility & z-index : CSS

Visibility

  Visibility

CSS Visibility Property: 

  • The visibility property is used to hide or show an HTML element without changing the layout of the page.
  • The hidden element uses the space on the page because it is still there, but it is not visible to the user.
  • but it is still occupying the space on the page.


Difference Between display:none; and visibility:hidden; 

There is a minor difference between the display: none; and visibility: hidden; the property of CSS.

  • display: none; - It completely removes an HTML tag from the web page like it was never there.
  • visibility: hidden; - It makes the tag invisible but will not remove the element, and it will still occupy the space on the page.


Z-Index Property

Z-Index Property

What if one box overlaps the other? Which box will be visible to the user? This is where the z-index property comes into the picture. So, whenever HTML elements collapse with each other, then the element with a smaller z-index value will be covered by the element with a larger z-index value.

Note: Z-index does not work on static position value. It only works on the elements with position: relative, absolute, fixed, or sticky.

Post a Comment

0 Comments