I hav开发者_如何学运维e 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
Instead of putting display: none;
on your div, put visibility: hidden;
. It will be invisible, but still take up space.
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.
if you can use visiblity hidden property instead of display:none you can achieve what you want.
When you do visibilty:hidden it just make the elements opacity to 0 while the element is still retaining its space.
Or if you are playing with jQuery fadeIn/fadeOut and need that spot to remain empty but with reserved height, then just wrap around needed element with fixed height, for example:
<div style="height: 52px;">
<img id="loader" src="loader.gif />
</div>
精彩评论