I have a single Bootstrap 4 collapse as follows...
<a data-toggle="collapse" href="#collapseNEWS" aria-expanded="true" aria-controls="collapseNEWS"><i class="fa fa-chevron-circle-up" aria-hidden="true"></i></a>
<div class="row collapse in" id="collapseNEWS">Content</div>
This automatically displays the content unless the font awesome icon is clicked. I am displaying the fa-chevron-circle-up icon upon initial load.
Once the icon is clicked, the content closes and I'd like to show the fa-chevron-circle-down icon instead. How would I achieve this?
I've looked at the alpha documentation: http://v4-alpha.getbootstrap.com/components/collapse/
...but I'm not clear how I establish the state to show either...
<i class="indicator fa fa-chevron-circle-up" aria-hidden="true"></i>
or...
<i class="indicator fa fa-chevron-circle-down" aria-hidden="true"></i>
Thank you NJ
You can add
toggleClass()
toonclick
event of<a></a>
element and additional classfa-rotate-180
for element ofFont Awesome icon
.To extend this further - now using Bootstrap 4 Beta if it makes a difference:
This won't work when the initial state is collapsed - the icon will be reversed. Clicking the button through a cycle will fix it - but it'd be nice to have it right to begin with. The secret: add
to the toggling link(s). An example with a clickable text heading as well as the icon:
I also find the plus/minus symbols more intuitive - with arrows, I'm never quite sure if it means "current status is opened/closed" or "press this to open/close". Based on tree views, among others, I'm used to "+" means "closed/click to open", and "-" means "open/click to close". So while not directly part of the question I'll leave this for others to find (full credit to @tmg above for format - I just plugged in the "correct" characters):
Using Rails and Bootstrap 4 with Fontawesome 5.5
This didn't quite work for me, It was flipping it on the re-close. I had to add another state control:
Solution with no FontAwesome unicode and no JavaScript:
Example:
HTML:
CSS:
You can add the font-awesome icon with custom CSS (content property):
Just use
<i class="fa"></i>
andExample in codepen
For SASS version of FontAwesome 5, use the
fa-content()
mixinHTML:
SASS:
I prefer using chevron in a circle background