Bootstrap Accordion Issue With Arrow

How do I fix the Bootstrap Accordion Arrow direction?

First make sure that you use unique id's for both .accordion-button and .accordion-collapse.


If it is collapsed by default, add the .collapsed on the .accordion-button and set aria-expended to true.

.accordion-button::after {
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23A81912'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e");
}

.accordion-button:not(.collapsed)::after {
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23A81912'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e");
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js" integrity="sha384-eMNCOe7tC1doHpGoWe/6oMVemdAVTMs2xqW4mwXrXsW0L84Iytr2wi5v2QjrP/xp" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.min.js" integrity="sha384-cn7l7gDp0eyniUwwAZgrzD06kc/tftFf19TOAs2zVinnD/C7E91j9yyk5//jjpt/" crossorigin="anonymous"></script>

<div class="accordion" id="accordion">
<div class="accordion-item">
<h4 class="accordion-header" id="headingOne">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Current Courses
</button>
</h4>
<div id="collapseOne" class="accordion-collapse collapse" aria-labelledby="headingOne" data-bs-parent="#accordion">
<div class="accordion-body">
{current_courses}
<p class="course"><a class="course-link" href="{current_courses:link_to_course}">{current_courses:title}</a> {current_courses:hours} CPE Hours {current_courses:course_date}</p>
{/current_courses}
</div>
<!-- /. accordion-body -->
</div>
<!-- /.collapse -->
</div>
<!-- /.accordion-item -->

Bootstrap accordion with arrows

Problem is in space between selectors:

.panel-heading [data-toggle="collapse"]:after
^------- // remove this space to make this selector work

Now you are selecting all elements having data-toggle attribute which are descendants of .panel-heading. It should be:

.panel-heading[data-toggle="collapse"]:after

.panel-heading {  position: relative;}.panel-heading[data-toggle="collapse"]:after {  font-family: 'Glyphicons Halflings';  content: "\e072"; /* "play" icon */  position: absolute;  color: #b0c5d8;  font-size: 18px;  line-height: 22px;  right: 20px;  top: calc(50% - 10px);
/* rotate "play" icon from > (right arrow) to down arrow */ -webkit-transform: rotate(-90deg); -moz-transform: rotate(-90deg); -ms-transform: rotate(-90deg); -o-transform: rotate(-90deg); transform: rotate(-90deg);}.panel-heading[data-toggle="collapse"].collapsed:after { /* rotate "play" icon from > (right arrow) to ^ (up arrow) */ -webkit-transform: rotate(90deg); -moz-transform: rotate(90deg); -ms-transform: rotate(90deg); -o-transform: rotate(90deg); transform: rotate(90deg);}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script><link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/><!-- Accordion START -->      <div class="panel-group" id="accordion">        <div class="panel panel-default">          <div class="panel-heading accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" data-target="#collapseOne">            <h4 class="panel-title">Test1</h4>
</div> <div id="collapseOne" class="panel-collapse collapse"> <div class="panel-body"> <p>sadfsadfsdaf sadf</p> </div> </div> </div> <div class="panel panel-default"> <div class="panel-heading accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" data-target="#collapseTwo"> <h4 class="panel-title">Test2</h4>
</div> <div id="collapseTwo" class="panel-collapse collapse"> <div class="panel-body"><p>Bla bla bla</p> </div> </div> </div> </div> <!-- Accordion END -->

Add up/down arrows to Bootstrap Accordion

There are CSS-only solutions that make use of some of the triggers that Bootstrap's accordion already has in place. For example, an expanded .panel-title has a value of [area-expanded="true"] which we can use as a CSS Selector.

With that in mind you can use code like this:

.panel-title {
position: relative;
}

.panel-title::after {
content: "\f107";
color: #333;
top: -2px;
right: 0px;
position: absolute;
font-family: "FontAwesome"
}

.panel-title[aria-expanded="true"]::after {
content: "\f106";
}

/*
* Added 12-27-20 to showcase full title clickthrough
*/

.panel-heading-full.panel-heading {
padding: 0;
}

.panel-heading-full .panel-title {
padding: 10px 15px;
}

.panel-heading-full .panel-title::after {
top: 10px;
right: 15px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<div class="panel-group" id="accordion">

<!-- First Panel -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title" data-toggle="collapse" data-target="#collapseOne">Collapsible Group Item #1</h4>
</div>

<div id="collapseOne" class="panel-collapse collapse">
<div class="panel-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid.
</div>
</div>
</div>

<!-- Second Panel -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title" data-toggle="collapse" data-target="#collapseTwo">Collapsible Group Item #2</h4>
</div>

<div id="collapseTwo" class="panel-collapse collapse">
<div class="panel-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid.
</div>
</div>
</div>

<!-- Third Panel -->
<div class="panel panel-default">
<div class="panel-heading panel-heading-full">
<h4 class="panel-title" data-toggle="collapse" data-target="#collapseThree">Collapsible Group Item #3 (panel-heading-ful)</h4>
</div>

<div id="collapseThree" class="panel-collapse collapse">
<div class="panel-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid.
</div>
</div>
</div>

</div>

css accordion right arrow and down arrow not working properly

Add class collapsed on your <a> tags. They render first as open because of the missing class

https://jsfiddle.net/jpgc24rg/

<a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">

Bootstrap accordion icons not working on collapsed states

Change your css to:

.panel-heading-one .accordion-toggle:after{
font-family: 'Glyphicons Halflings';
content: "\e114";
float: right;
color: #ffffff;
height: 24px;
width: 40px;
background-color: #000000;
}

.panel-heading-one .accordion-toggle[aria-expanded="true"]:after {
/* symbol for "opening" panels */
content: "\e113";
}

.panel-heading-one .accordion-toggle[aria-expanded="false"]:after {
/* symbol for "collapsed" panels */
content: "\e114";
}

And it will work perfectly.

Extra: In your accordion you have used same href='#collapseThree'
for last and second last item. When you will click on last element, it
will open second last item. So change your href in last element.

Changing the color arrow in Bootstrap

Bootstrap uses background images in their accordion arrows. You could edit the fill property of the linked svg.

I checked up on the svg used on https://getbootstrap.com/docs/5.0/components/accordion/, and changed the color to white with css

.accordion-button:after {
background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23ffffff'><path fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/></svg>") !important;
}

Note here that I wrote fill="%23ffffff", this changes the color to #ffffff (%23 is parsed to #)

You can find my codepen here

I would like to add that I don't think this is the most elegant way of solving this. You might want to change the content of the :after element of the .accordion-button.

Take a look at Adding arrows to the right using Bootstrap Accordion



Related Topics



Leave a reply



Submit