How to display and hide a div with CSS?

mridul picture mridul · Dec 15, 2013 · Viewed 282.4k times · Source

In my script there are three divs. I want to display div with class="ab" when I hover on first line and display div with class="abc", when hover on second line. Otherwise I want to display div with class="a" by default.

But it never displays the div with class="a".

Here is my JSFiddle of my problem: JSFiddle Link

Answer

multiplatform picture multiplatform · Jun 5, 2014

To hide an element, use:

display: none;
visibility: hidden;

To show an element, use:

display: block;
visibility: visible;

The difference is:

Visibility handles the visibility of the tag, the display handles space it occupies on the page.

If you set the visibility and do not change the display, even if the tags are not seen, it still occupies space.