Search code examples
htmlcssalignmentarabicbootstrap-5

How to reverse the accordion-button content in bootstrap 5


I'm coding a website in Arabic language content.
Problem: The content of the accordion-button should be reversed (the question in the right,the down arrow in the left). How can I solve it?

<!-- Bootstrap 5.0.x library -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">



<!-- Body -->
<div class="accordion accordion-flush" id="questions">
  <!--Begining of the item-->
  <div class="accordion-item">
    <h2 class="accordion-header" id="flush-headingOne">
      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#quest_1">
            السؤال الأول
          </button>
    </h2>
    <div id="quest_1" class="accordion-collapse collapse" data-bs-parent="#questions">
      <div class="accordion-body text-end">
        الإجابة على السؤال الأول
      </div>
    </div>
  </div>
  <!--Ending of the item-->
</div>


Solution

  • simply add dir="rtl" (direction: Right-To-Left) to the button. If you want to change the whole website to an "arabic layout" you could also add it to the <html> tag directly: <html lang="ar" dir="rtl">

    <!-- Bootstrap 5.0.x library -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    
    
    
    <!-- Body -->
    <div class="accordion accordion-flush" id="questions">
      <!--Begining of the item-->
      <div class="accordion-item">
        <h2 class="accordion-header" id="flush-headingOne">
          <button dir="rtl" class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#quest_1">
                السؤال الأول
              </button>
        </h2>
        <div id="quest_1" class="accordion-collapse collapse" data-bs-parent="#questions">
          <div class="accordion-body text-end">
            الإجابة على السؤال الأول
          </div>
        </div>
      </div>
      <!--Ending of the item-->
    </div>