tags:

views:

64

answers:

3

I'm using "visibility:hidden" to hide certain elements, but they still take up space on the page while hidden.

How can I make them totally disappear visually, as though they are not in the DOM at all (but without actually removing them from the DOM)?

+13  A: 

Try setting display:none to hide and set display:block to show.

Huusom
its not possible to remove element from dom man. by using this option also. read the question
Pranay Rana
not all items should be `display: block`, some will have to be set to `display: inline` (such as `<span>` or `<a>` or `<img>` DOM elements).
Mauro
I'll just remove the 'display:none' to show.
ripper234
@pranay the question says to hide them not to remove them from the DOM.
Mauro
@pranay: The question is not very well expressed but Huusom is solving the problem the user is having.
Claudio Redi
@Claudio - feel free to edit if you can improve it.
ripper234
@ripper234: sorry. Didn't mean to be rude :-(. I tried to say that your idea seemed to be hiding the element and avoid taking the space. You didn't care if the element was removed or not of the DOM.
Claudio Redi
@Claudio - no offence taken :) Cheers.
ripper234
+2  A: 

use style instead like

<div style="display:none;"></div>
Salil
A: 

display:none to hide and set display:block to show.

Pranay Rana
He asks about removing it visually, "as though they are not in the DOM". Not about removing them from the actual DOM.
Arve Systad
visiblity:hidden do same thing as display:none
Pranay Rana
@Arve Systad read this line "i'm using "visibility:hidden" to hide certain elements, but they still take up space on the page while hidden."
Pranay Rana
question states not to remove them from the DOM only to make them disappear. `as though they are not in the DOM at all (but without actually removing them from the DOM)`
Mauro
@pranay: `visibility: hidden` only stops the display of content but still uses vertical/horizontal space, display:none removes the vertical/horizontal space for the element.
Mauro
No it doesn't. visibility: hidden; makes the element invisible, but it still takes up space. display: none; makes the document behave as if it was never there.
Olly Hodgson
Delete this answer then.
BalusC