I'm using the collapse with transitions. The code below works but because I have 10px padding in my stylesheet I see the div collapse but stop 10px before it should and then vanish. The reverse is true on expanding as the div expands to 10px greater than it should before snapping back to the correct size.
HTML
<div ng-controller="MainCtrl" class="box-content collapse" id="mybox">
Lorem ipsum ...
</div>
CSS
.box-content{
background: red;
padding: 10px;
}
To control (show/hide) the collapsible content, add the data-toggle="collapse" attribute to an <a> or a <button> element. Then add the data-target="#id" attribute to connect the button with the collapsible content (<div id="demo">).
You can think of padding/border as a sort of wall; if it sits between two margins, they can't collapse, because there's a wall in the way. The width doesn't matter, either; even 1px of padding will interfere with margin collapse.
How it works. The collapse JavaScript plugin is used to show and hide content. Buttons or anchors are used as triggers that are mapped to specific elements you toggle. Collapsing an element will animate the height from it's current value to 0 .
Generally, we recommend using a button with the data-bs-target attribute. While not recommended from a semantic point of view, you can also use a link with the href attribute (and a role="button" ). In both cases, the data-bs-toggle="collapse" is required.
You have to wrap your content in .collapse and if you want to have padding, you can set CSS of your wrapper.
HTML
<div ng-controller="MainCtrl" class="box-content collapse" id="mybox">
<div class='wrapper'>
Lorem ipsum ...
</div>
</div>
CSS
.wrapper{
padding: 10px;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With