11/08/2016

CSS Display and Visibility

In CSS  display property defines how an element is displayed (used for controlling layout). 
The visibility property defines whether an element should be visible or hidden.

CSS Display Property

In HTML each and every element has a default display value either block or inline.

A block value specifies the full width available for an element and by default use a line break before and after it.

Some common HTML elements which have the display value as block are < h1 >, < p >, < li >, < div > etc. 

An inline value specifies the necessary width of the element only, and never force for line breaks before and after the element.

Some common HTML elements which have the display value as inline are < span >, < a > etc.

we can change the display of any element by using the CSS display property. Below is the example:

h1 
{
 display: inline;
}
a 
{
    display: block;
}

Hiding any Element - using display:none or visibility:hidden

Any element can be hide by using the CSS display or visisbility property. 

using display:none property

This property hides an element and it will not take any space for the element on the webpage.

 h1
 {
  display: none;
 }

using visibility:hidden property

This property hides an element but still it will take the same space for the element as before on the webpage.

 h1 
 {
  visibility: hidden;
 }