Bootstrap Collapse Class Doesn't Toggle Correctly
I am trying to use the Bootstrap collapse class. I have two issues. The first is when I click my collapse button initially, it takes a second click to collapse the div. Second, whe
Solution 1:
Try this snippet. I have changed some classes
h2 {
margin: 0;
display: inline-block;
}
<linkrel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css"integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy"crossorigin="anonymous"><divstyle="border: 3px solid #A9A9A9"><h2>Info</h2><buttonclass="btn btn-link collapsed"type="button"data-toggle="collapse"data-target="#collapseExample"aria-expanded="false"aria-controls="collapseExample">
collapse
</button><divclass="collapse"id="collapseExample"><span>test</span></div></div><scriptsrc="https://code.jquery.com/jquery-3.2.1.slim.min.js"integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"crossorigin="anonymous"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js"integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4"crossorigin="anonymous"></script>
EDITED:
Loading with expanding the content
Changed log: aria-expanded="true"
and adding show class to
<div class="collapse show"id="collapseExample">
h2 {
margin: 0;
display: inline-block;
}
<linkrel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css"integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy"crossorigin="anonymous"><divstyle="border: 3px solid #A9A9A9"><h2>Info</h2><buttonclass="btn btn-link collapsed"type="button"data-toggle="collapse"data-target="#collapseExample"aria-expanded="true"aria-controls="collapseExample">
collapse
</button><divclass="collapse show"id="collapseExample"><span>test</span></div></div><scriptsrc="https://code.jquery.com/jquery-3.2.1.slim.min.js"integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"crossorigin="anonymous"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js"integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4"crossorigin="anonymous"></script>
For more information you can refer bootstrap 4 documentation. The relevant link is provided below. https://getbootstrap.com/docs/4.0/components/collapse/
Post a Comment for "Bootstrap Collapse Class Doesn't Toggle Correctly"