bootstrap initially collapsed element

前端 未结 8 912
长发绾君心
长发绾君心 2020-12-15 02:29

I am using the bootstrap template and I would like to change the way the accordion works by default.

How can I get the toggle to be closed when page is first seen (u

相关标签:
8条回答
  • 2020-12-15 02:49

    need to delete show from class:

    <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
    

    It have to be

    <div id="collapseOne" class="collapse" aria-labelledby="headingOne" data-parent="#accordion">
    
    0 讨论(0)
  • 2020-12-15 02:51

    I just added class hide to the div before "card-body" and it hidden by default.

    <div id="collapseOne" class="collapse hide" aria-labelledby="headingOne" data-parent="#accordion">

    0 讨论(0)
  • 2020-12-15 02:57

    If removing the in class doesn't work for you, such was my case, you can force the collapsed initial state using the CSS display property:

    ...
    <div id="collapseOne" class="accordion-body collapse" style="display: none;">
    ...
    
    0 讨论(0)
  • 2020-12-15 03:02

    When you expand or collapse accordion it just adds/removes a class "in" and sets the height:auto or 0 to the accordion div.

    Demo

    So in your accordion when you define it just remove "in" class from the div as below. Whenever you expand an accorion it just adds the "in" class to make it visible.

    If you render the page with "in" bootstrap looks for the class and it will make the div's height:auto, if it not present it will be at zero height.

    <div id="collapseOne" class="accordion-body collapse">
    
    0 讨论(0)
  • 2020-12-15 03:02

    Just add class "show" to the collapsing element's class, bootstrap will use js dynamically to remove it to collapse and show

    0 讨论(0)
  • 2020-12-15 03:05

    There is a class in accordian which just adjust height from height:auto or 0 to the accordian div.

    if you remove 'in' class and when you click on it, bootstrap adds 'in' class again and now content will be visible

    <div id="collapseOne" class="accordion-body collapse">
    ....
    </div>
    
    0 讨论(0)
提交回复
热议问题