5

I am trying to get my accordion buttons to keep a purple background colour when shown and return to white when closed, and also to remove the blue highlight border once clicked. I am working with boostrap v5. This is the CSS that I've tried, which achieves the results in the images below:

    .accordion-button:link, .accordion-button:visited, .accordion-button:hover, .accordion-button:focus ,.accordion-button:active  {
  background-color: #5500C9 !important;
    color:#FFF !important;
    text-decoration: none !important;
     border: hidden !important;
          }

<div class="accordion-item ">
            <h2 class="accordion-header" id="headingOne">
              <button class="accordion-button collapsed mb-3 border-bottom" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne"> How to sell my motorbike? </button>
            </h2>
            <div id="collapseOne" class="accordion-collapse collapse border mb-3 bg-dark text-white" aria-labelledby="headingOne" data-bs-parent="#motorbikeAccordion">
              <div class="accordion-body"> <strong>How do I sell my motorbike to you?</strong> Selling your motorbike to us is easy. We operate three simple steps. Enter your motorbike's registration in the box above and confirm we've found the right bike. After that we will ask for some details about your motorbike such as the mileage, condition and accessories. Once we've received your contact details we will be in touch within just 24 hours. </div>
            </div>
          </div>

1: The collapsed state:

Collapsed

2: Hover state:

enter image description here

3: Show state:

enter image description here

4: Final state when you remove focus (click away)

enter image description here

The bootstrap offical docs are extremely limited on information for accordions.

Question: I'd like to remove the border on the show state (3), and on the final state when the accordion is open and the user has clicked away, for the background to remain purple until the accordion is closed and then returned to white.

1 Answer 1

11

After digging around in the bootstrap CSS I found the classes used:

.accordion-button:not(.collapsed) {
  color: #FFF  !important;
  background-color: #5500C9 !important;
}



.accordion-button:link, .accordion-button:visited, .accordion-button:hover, .accordion-button:active  {
  background-color: #5500C9 !important;
    color:#FFF !important;
    text-decoration: none !important;
     border: hidden !important;
       border-color: #FFF !important;
    box-shadow: 0px !important;

      
}

.accordion-button:focus {
  z-index: 3;
  border-color: #FFF !important;
  outline: 0;
  box-shadow: 0 0 0 .25rem #FFF !important;
}

Bonus Content:

    .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='%230c63e4'%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");
  transform: rotate(180deg)

}

This is to change to the up/down arrow svg

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.