0

I have 5 divs. Each time I want only one of them to be shown in the middle of the screen. The problem is that the hidden divs takes space. Each div contain a lot of information so I don't want to create it each time I need to show it.

I simply used: visibility="visible" or visibility="hidden".

Are there other possibilities?

Fabrizio Calderan
  • 120,726
  • 26
  • 164
  • 177
user2004403
  • 193
  • 2
  • 13
  • 1
    use `display: block` and `display: none` instead. – Mr_Green May 09 '13 at 13:56
  • See [What is the difference between visibility:hidden and display:none?](http://stackoverflow.com/questions/133051/what-is-the-difference-between-visibilityhidden-and-displaynone) – Alex K. May 09 '13 at 13:57

4 Answers4

3

You need to use display:none to hide an element completely from the layout instead, which is documented as:

none - This value causes an element to not appear in the document. It has no effect on layout.

visibility:hidden will leave an invisible box, which is the problem you are encountering. From the documentation:

hidden - The generated box is invisible (fully transparent, nothing is drawn), but still affects layout. Furthermore, descendants of the element will be visible if they have 'visibility: visible'.

The default CSS display value for a <div> is display:block, so to show the <div> again, just set the element back to display:block. Note that there are other values for display, so take care to set it back to it's original value (which might not necessarily be the default value).

andyb
  • 43,435
  • 12
  • 121
  • 150
0

use display:none if you use css or .hide() if you use jquery

Johnny000
  • 2,058
  • 5
  • 30
  • 59
0

I would normally just use the jquery 'hide' method. This should hide the div's without them taking up any space on the screen.

SteveP
  • 18,840
  • 9
  • 47
  • 60
0

Even invisible elements take up space on the page. Use the display property to create invisible elements that do not take up space.

display:none;

Read this for more info --> https://developer.mozilla.org/en-US/docs/CSS/display

Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111