Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep height of auto height DIV when content gets hidden

Tags:

html

height

I have a div with auto height and and image in it. When I click to get the image hidden, the div container should stay at its height. I know I could achieve this with a fixed height div, but because there are several divs / images with various heights, I can't do it that way.

https://jsfiddle.net/t6w3fkg8/

$(".content").click(function(){
"use strict";
$(this).hide();

});

like image 805
JPC Avatar asked Nov 28 '25 23:11

JPC


1 Answers

display:none means that the tag in question will not appear on the page at all (although you can still interact with it through the dom). There will be no space allocated for it between the other tags.

visibility:hidden means that unlike display:none, the tag is not visible, but space is allocated for it on the page. The tag is rendered, it just isn't seen on the page.

You probably are using display:none at the moment. Try with visibility:hiddeninstead.

Edit: I updated your Fiddle with visibility:hidden: https://jsfiddle.net/xhmp8wj7/1/

like image 70
Natrium Avatar answered Nov 30 '25 12:11

Natrium



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!