Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 4 Collapse show state with Font Awesome icon

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

like image 987
NathonJones Avatar asked Aug 16 '16 08:08

NathonJones


People also ask

How do I style a bootstrap collapse?

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.

Is Font Awesome include in bootstrap 4?

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.


1 Answers

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

like image 149
tmg Avatar answered Sep 28 '22 04:09

tmg