Skip to content

Instantly share code, notes, and snippets.

@absent1706
Last active July 24, 2021 12:10
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save absent1706/6ebcee9f2d7992e26f073905fc28ca97 to your computer and use it in GitHub Desktop.
Save absent1706/6ebcee9f2d7992e26f073905fc28ca97 to your computer and use it in GitHub Desktop.
Bootstrap-collapse rotate icon. https://jsfiddle.net/1L3xy40k/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
[data-toggle="collapse"][aria-expanded="true"] > .js-rotate-if-collapsed
{
-webkit-transform: rotate(180deg);
-moz-transform: rotate(180deg);
-ms-transform: rotate(180deg);
-o-transform: rotate(180deg);
transform: rotate(180deg);
}
</style>
</head>
<body>
<h3>Initially closed</h3>
<div style="cursor: pointer" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false">
Header
<span class="glyphicon glyphicon-menu-down js-rotate-if-collapsed"></span>
</div>
<div id="collapseExample" class="collapse">
Body
</div>
<hr>
<h3>Initially opened</h3>
<div style="cursor: pointer" data-toggle="collapse" data-target="#collapseExample2" aria-expanded="true">
Header
<span class="glyphicon glyphicon-menu-down js-rotate-if-collapsed"></span>
</div>
<div id="collapseExample2" class="collapse in">
Body
</div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
@acal
Copy link

acal commented Aug 29, 2017

This one was the best solution out of many that I searched for and just with a CCS rule and the existing BS.js....thanks!!!! I found it especially annoying problem since I was using multiple collapse sections and when (with custom js/jquery) I clicked on section's icon all the other sections would flip state as well. This solution allows for discrete behavior of each icon. Cheers!

@imnickvaughn
Copy link

"using multiple collapse sections and when (with custom js/jquery) I clicked on section's icon all the other sections would flip state as well"

Hey I am having trouble with this exact problem.... but its actually with this solution... How did you solve it? I can't get just one of the sections to collapse. Here is my fiddle... https://jsfiddle.net/vaughnick/f4gkxx4n/

Thanks for any help you can provide.

@AleksNikos
Copy link

Thanks, its work

@cooljoe61
Copy link

Thanks, works like a charm

@ArturasGerasimov
Copy link

Thanks, worked really fine!

@MohdZish
Copy link

This is awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment