This website stores cookies. Click here to accept them.cookie information page

"visibility" category

hiding and showing HTML with CSS and Javascript

23rd January 2012
Categories: css, visibility

Alongside Ajax (see previous article), one of the weapons in the web developer's arsenal for combating a stodgy user interface is the ability to hide and show HTML elements.

There are two basic ways to hide and show elements in css: one uses the "display" property:

#myHiddenDiv
{
  display:none;
}

#myVisibleDiv
{
  display:block;
}

And the other uses the "visibility" property: 

#myHiddenDiv
{
  visibility:hidden;
}

#myVisibleDiv
{
  visibiity:visible;
}

The display:none property acts as if the element never existed - i.e. the element takes up no space on the screen - while the 'visibility: hidden' property leaves a gap where the element should be visible.

If you're using jQuery to make something appear and disappear, you can use hide and show methods - your code should look something like this:

$('#myHiddenDiv').show();

NB. If you want to make something dynamically appear and it's overlapping other elements when you don't want it to - try making it display normally first in order to troubleshoot. It may be that it has a parent which has relative positioning.

© Integritec (UK) Ltd 2014

Oxford House
1600 John Smith Drive
Oxford Business Park South
Oxford OX4 2JY

01865 596 144

Oxford Web is a division of Integritec (UK) Ltd.