Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap collapse and padding issue

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;
}
like image 329
user1853235 Avatar asked Sep 23 '13 10:09

user1853235


People also ask

How do I stop a Bootstrap collapse?

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">).

Can padding collapse?

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 does collapse work in Bootstrap?

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 .

Which BS 5 attribute and value is used to create a collapse system?

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.


1 Answers

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;
}
like image 188
Watcharakrit Phantu Avatar answered Sep 22 '22 08:09

Watcharakrit Phantu