Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how reserve height while display is none

Tags:

I have a div with default display:none. how do I reserve the height so when the div shows, it does not reshift the elements around it? thanks

like image 472
user384080 Avatar asked Oct 24 '10 05:10

user384080


People also ask

Does display none takes up space?

display:none removes the element from the document. It does not take up any space.

What happens when display none?

Unlike the visibility property, which leaves an element in normal document flow, display: none essentially removes the element completely from the document. The attached element does not take up any space, even though it's still in the source code. As far as the browser's concerned, the item is gone.

How do you counter display none?

display: none doesn't have a literal opposite like visibility:hidden does. The visibility property decides whether an element is visible or not. It therefore has two states ( visible and hidden ), which are opposite to each other.

Does display none improve performance?

Display none don't reduce the size of the dom, just make the element not visible, like visible hidden, without occupies the visual space. Display none don't improve the performance because the goal of virtual scrolling is reduce the number of the elements into the dom.


2 Answers

Instead of putting display: none; on your div, put visibility: hidden;. It will be invisible, but still take up space.

like image 88
John Calsbeek Avatar answered Nov 04 '22 16:11

John Calsbeek


Use visibility: hidden instead of display: none. Your element won't display, but its dimensions still apply and affect other elements because it's still a part of the page flow.

like image 42
BoltClock Avatar answered Nov 04 '22 15:11

BoltClock