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
Just add data-toggle="collapse" and a data-target to the element to automatically assign control of one or more collapsible elements. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element.
Bootstrap 4 does not have its own icon library (Glyphicons from Bootstrap 3 are not supported in BS4). However, there are many free icon libraries to choose from, such as Font Awesome and Google Material Design Icons.
You can add the font-awesome icon with custom CSS (content property):
Just use <i class="fa"></i>
and
[data-toggle="collapse"] .fa:before { content: "\f139"; } [data-toggle="collapse"].collapsed .fa:before { content: "\f13a"; }
Example in codepen
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With