ashwinx ashwinx - 2 months ago 7
CSS Question

Wrap div around a hidden div

I have a parent div "d1" and it contains a child div "d2". d2's visibility changes every time a particular button is clicked. What I need is to wrap d1 around its other contents when d2 is hidden and expand when d2 is visible.
Its something like this:

<div id="d1">
<p>Content which is visible all the time</p>
<button onclick="changed2()">Alter d2 visibility</button>
<div id="d2" style="visibility:hidden;">
</div>
</div>


I wanted to know if anything like this is possible through HTML or CSS without using things like Bootstrap.
Thank you.

Era Era
Answer

Use display:none and display: block instead of using visibility: hidden and visibility: visible

as display:none will hide the element completely and its space.