Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hidden HTML elements take space

I'd like to make some empty hidden elements (iframes would be nice, paragraphs would do) that Javascript would later fill and modify. I have not been able to figure out how to keep these elements from taking up space. I've turned off margins and padding and set height to zero but still end up with blank space.

I'd like to see an example of an hidden element that takes no space on the page. Actually, I'd like to see the HTML, CSS, and Javascript. :-).

like image 474
Mike D Avatar asked Sep 13 '10 13:09

Mike D


People also ask

How do you make the hidden element not take up space?

Look, instead of using visibility: hidden; use display: none; . The first option will hide but still takes space and the second option will hide and doesn't take any space.

Does visibility Hidden takes space?

visibility:hidden hides the element, but it still takes up space in the layout. display:none removes the element from the document. It does not take up any space.

How would you hide an element on a webpage so it doesn't take space in the flow of the page but is still present in code?

visibility: hidden means it will be hidden, BUT will remain in the flow of the website. Essentially, visibility: hidden will not show the element, but will retain the space it takes up. Whereas display: none completely removes it.

Which property is used to hide an element without using any space on the page?

The visibility CSS property shows or hides an element without changing the layout of a document.


3 Answers

If you're using visibility: hidden; you should be using display: none; instead.

like image 107
Jess Avatar answered Oct 01 '22 10:10

Jess


I assume you are using visibility: hidden? As you have seen, this will hide it, but will still take up space.

However, using display: none will hide it and remove it from the page layout.

like image 34
James Hull Avatar answered Oct 01 '22 09:10

James Hull


#myelement { display:none; } should already do it via CSS, using <div id="myelement"></div>

like image 1
thedanielhanke Avatar answered Oct 01 '22 08:10

thedanielhanke