skip to Main Content

i already create the code and the result like this
enter image description here

and i want when i press the other accordion, the right side image will change like this
enter image description here

i already try to create, but what i got is the image stacking and not changing in the same place like this
enter image description here

i use this code, and i need help to fix this problem

    <section class="various__sect">

        <div class="container">
            <div class="row">
                <div class="col-6 various__left__group">
                    <div class="various__title">
                        Various Kinds of Finances Products
                    </div>
                    <div class="various__accordion">
                        <div class="accordion accordion-flush" id="accordionFlushExample">
                            <div class="accordion-item">
                                <h2 class="accordion-header" id="flush-headingOne">
                                <button id="collapseOne" class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#flush-collapseOne" aria-expanded="false" aria-controls="flush-collapseOne">
                                    1. We have features that help your finances
                                </button>
                                </h2>
                                <div id="flush-collapseOne" class="accordion-collapse collapse show" aria-labelledby="flush-headingOne" data-bs-parent="#accordionFlushExample">
                                    <div class="accordion-body">
                                        With this scan features, it can make transactions faster and safer, of course
                                        <div class="mt-3">
                                            <a href="">Learn More <span class="bi bi-arrow-right-short"></span></a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="accordion-item">
                                <h2 class="accordion-header" id="flush-headingTwo">
                                <button id="collapseTwo" class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#flush-collapseTwo" aria-expanded="false" aria-controls="flush-collapseTwo">
                                    2. All kinds of activities regarding finances
                                </button>
                                </h2>
                                <div id="flush-collapseTwo" class="accordion-collapse collapse" aria-labelledby="flush-headingTwo" data-bs-parent="#accordionFlushExample">
                                <div class="accordion-body">
                                    With this scan features, it can make transactions faster and safer, of course
                                    <div class="mt-3">
                                        <a href="">Learn More <span class="bi bi-arrow-right-short"></span></a>
                                    </div>
                                </div>
                                </div>
                            </div>
                            <div class="accordion-item">
                                <h2 class="accordion-header" id="flush-headingThree">
                                <button id="collapseThree" class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#flush-collapseThree" aria-expanded="false" aria-controls="flush-collapseThree">
                                    3. Various of needs regarding finance here
                                </button>
                                </h2>
                                <div id="flush-collapseThree" class="accordion-collapse collapse" aria-labelledby="flush-headingThree" data-bs-parent="#accordionFlushExample">
                                    <div class="accordion-body">
                                        With this scan features, it can make transactions faster and safer, of course
                                        <div class="mt-3">
                                            <a href="">Learn More <span class="bi bi-arrow-right-short"></span></a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="accordion-item">
                                <h2 class="accordion-header" id="flush-headingFour">
                                <button id="collapseFour" class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#flush-collapseFour" aria-expanded="false" aria-controls="flush-collapseFour">
                                    4. Only here you will get various benefits
                                </button>
                                </h2>
                                <div id="flush-collapseFour" class="accordion-collapse collapse" aria-labelledby="flush-headingFour" data-bs-parent="#accordionFlushExample">
                                <div class="accordion-body">
                                    With this scan features, it can make transactions faster and safer, of course
                                    <div class="mt-3">
                                        <a href="">Learn More <span class="bi bi-arrow-right-short"></span></a>
                                    </div>
                                </div>
                                </div>
                            </div>
                            </div>
                    </div>
                </div>
                <div class="offset-1 col-5">

                    <div class="collapse show multi-collapse" id="flush-collapseOne">
                        <div class="img__collapse">
                            <img src="assets/img/img-various.webp" alt="">
                        </div>
                    </div>
                    <div class="collapse multi-collapse" id="flush-collapseTwo">
                        <div class="img__collapse">
                            <img src="assets/img/img-various.webp" alt="">
                        </div>
                    </div>
                    <div class="collapse multi-collapse" id="flush-collapseThree">
                        <div class="img__collapse">
                            <img src="assets/img/img-various.webp" alt="">
                        </div>
                    </div>
                    <div class="collapse multi-collapse" id="flush-collapseFour">
                        <div class="img__collapse">
                            <img src="assets/img/img-various.webp" alt="">
                        </div>
                    </div>

                </div>
            </div>
        </div>

    </section>

I’m using bootstrap 5 to create this

2

Answers


  1. You need to remove the any show classes from the right hand divs when you apply it to the one you want to show.

    $('div.collapse.multi-collapse').removeClass('show');
    
    Login or Signup to reply.
  2. Using Bootstrap 5, I have created this Accordion with a Tab View Section, Simply, I just combined the "tab" and "accordion" attributes and classes in the html tags.

    <!DOCTYPE html>
    <html lang="en">
        <head>
            <title></title>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <link href="css/style.css" rel="stylesheet">
    
            <!-- BootStrap 5 CDN -->
            <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
            <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    
        </head>
        <body>
        
    
            <div class="accordion-tab-section">
                <div class="container">
                    <div class="row pt-5">
                        <div class="col-lg-7">
                            <div  id="accordionExample" class="d-block accordion nav nav-tabs" role="tablist">
                                <div class="accordion-item" data-bs-toggle="tab" data-bs-target="#accordion-one" type="button" role="tab" aria-controls="accordion-one" aria-selected="true">
                                  <h2 class="accordion-header" id="headingOne">
                                    <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                                      Accordion Item #1
                                    </button>
                                  </h2>
                                  <div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
                                    <div class="accordion-body">
                                        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
                                        tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
                                        quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
                                        consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
                                        cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
                                        proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
                                    </div>
                                  </div>
                                </div>
                                <div class="accordion-item" data-bs-toggle="tab" data-bs-target="#accordion-two" type="button" role="tab" aria-controls="accordion-two" aria-selected="false">
                                  <h2 class="accordion-header" id="headingTwo">
                                    <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
                                      Accordion Item #2
                                    </button>
                                  </h2>
                                  <div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordionExample">
                                    <div class="accordion-body">
                                        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
                                        tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
                                        quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
                                        consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
                                        cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
                                        proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
                                    </div>
                                  </div>
                                </div>
                                <div class="accordion-item" data-bs-toggle="tab" data-bs-target="#accordion-three" type="button" role="tab" aria-controls="accordion-three" aria-selected="false">
                                    <h2 class="accordion-header" id="headingTwo">
                                    <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
                                      Accordion Item #3
                                    </button>
                                  </h2>
                                  <div id="collapseThree" class="accordion-collapse collapse" aria-labelledby="headingThree" data-bs-parent="#accordionExample">
                                    <div class="accordion-body">
                                        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
                                        tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
                                        quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
                                        consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
                                        cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
                                        proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
                                    </div>
                                  </div>
                                </div>
                              </div>
                        </div>
                        <div class="col-lg-5">
                            
                            <div class="tab-content d-flex justify-content-center align-items-center h-100" id="nav-tabContent">
                                <div class="tab-pane fade show active" id="accordion-one" role="tabpanel" aria-labelledby="accordion-one-tab"><h2>Accordion Item 1</h2></div>
                                <div class="tab-pane fade" id="accordion-two" role="tabpanel" aria-labelledby="accordion-two-tab"><h2>Accordion Item 2</h2></div>
                                <div class="tab-pane fade" id="accordion-three" role="tabpanel" aria-labelledby="accordion-three-tab"><h2>Accordion Item 3</h2></div>
                            </div>
                        </div>              
                    </div>
                </div>
               
            </div>
    
        </body>
    </html>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search