Bootstrap accordion collapse feature not functioning properly

I'm just starting out with HTML/CSS and as I follow a few tutorials, I've encountered an issue when attempting to implement an accordion example from https://getbootstrap.com/docs/4.0/components/collapse/. It seems like the problem stems from the CSS file. The .button class seems to be conflicting with the HTML code, causing this issue.

Here's the snippet of my HTML code:

        <section class="our-news section-margin">
            <div class="container">
                <div class="one-title" data-dsn-animate="up">
                    <div class="title-sub-container">
                        <p class="title-sub">Frequently Asked Questions</p>
                    </div>
                    <h2 class="title-main">What you need to know</h2>
                </div>

            <div class="accordion" id="accordionExample">
              <div class="card">
                <div class="card-header" id="headingOne">
                  <h2 class="mb-0">
                    <button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                      Collapsible Group Item #1
                    </button>
                  </h2>
                </div>

                <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionExample">
                  <div class="card-body">
                    Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
                  </div>
                </div>
              </div>
            </div>
          </div>
        </section>

The culprit might be in the CSS styling:

.button,
button:not([data-filter]):not(.mfp-arrow),
input[type="button"],
input[type="reset"],
input[type="submit"] {
  position: relative;
  width: auto;
  color: #fff;
  background-color: #090909;
  -moz-appearance: none;
  border: none;
  -webkit-appearance: none;
  appearance: none;
  display: inline-block;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 3px;
  line-height: 14px;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 0;
  padding: 20px 41px;
  margin-top: 0;
  -webkit-transition: background 0.3s, color 0.3s;
  -o-transition: background 0.3s, color 0.3s;
  transition: background 0.3s, color 0.3s;
  overflow: hidden;
}

.button:before,
button:not([data-filter]):not(.mfp-arrow):before,
input[type="button"]:before,
input[type="reset"]:before,
input[type="submit"]:before {
  content: "";
  background-color: rgba(54, 54, 54, 0.2);
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
}

Trying to debug, what do you think could be causing the issue?

Answer №1

Make sure to include the necessary jquery scripts in addition to your bootstrap setup. Simply insert this code snippet into your existing code:

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"gt;</script>

Witness it in action here:

.button,
button:not([data-filter]):not(.mfp-arrow),
input[type="button"],
input[type="reset"],
input[type="submit"] {
  position: relative;
  width: auto;
  color: #fff;
  background-color: #090909;
  -moz-appearance: none;
  border: none;
  -webkit-appearance: none;
  appearance: none;
  display: inline-block;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 3px;
  line-height: 14px;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 0;
  padding: 20px 41px;
  margin-top: 0;
  -webkit-transition: background 0.3s, color 0.3s;
  -o-transition: background 0.3s, color 0.3s;
  transition: background 0.3s, color 0.3s;
  overflow: hidden;
}

.button:before,
button:not([data-filter]):not(.mfp-arrow):before,
input[type="button"]:before,
input[type="reset"]:before,
input[type="submit"]:before {
  content: "";
  background-color: rgba(54, 54, 54, 0.2);
  height: 100% position: absolute;
  left: 0;
  top: 0;
  width: 0;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>



       <section class="our-news section-margin">
            <div class="container">
                <div class="one-title" data-dsn-animate="up">
                    <div class="title-sub-container">
                        <p class="title-sub">Frequently Asked Questions</p>
                    </div>
                    <h2 class="title-main">What you need to know</h2>
                </div>

            <div class="accordion" id="accordionExample">
              <div class="card">
                <div class="card-header" id="headingOne">
                  <h2 class="mb-0">
                    <button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                      Collapsible Group Item #1
                    </button>
                  </h2>
                </div>

                <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionExample">
                  <div class="card-body">
                    Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
                  </div>
                </div>
              </div>
            </div>
          </div>
        </section>

Answer №2

It appears that you may be missing some essential imports in your HTML file.

For more information, please refer to the documentation: https://getbootstrap.com/docs/4.0/getting-started/download/. Make sure to include all 4 links, with the last 2 placed before the first two.

Additionally, ensure that you are not using a button class. For accessing buttons, simply use:

button {
}

Instead of:

.button {
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Designing a hierarchical HTML dropdown menu for choosing an XML file for parsing using a jQuery script

I have successfully created a question and answer framework using Jquery and XML files. Users can choose a specific category of questions from a drop-down menu, which then displays the corresponding questions and answers from the selected XML file. While ...

Guide on displaying search results in separate boxes using HTML

I am struggling with organizing my search engine results in separate boxes on my website. Being new to HTML, I am unsure of how to achieve this layout. Currently, all the results are overlapping each other, and it's creating a messy display. Can anyon ...

Alter the background hue of alternate div elements within a row

The table I have contains multiple div elements, each corresponding to an item in an array. Within the table, there is a single tr, and the 1st and 2nd td are not directly related to the 3rd and 4th td. Each td in the table repeats a div element for the ...

I'm finding it a bit difficult to arrange the placement of these DIV

Struggling with a layout issue here. I have a total of 4 DIVs that I want to position in a specific way: Initially, I floated DIV 1 to the left and DIV 4 to the right, which worked as expected. However, things get messy as soon as I try to include DIVs 2 ...

What is preventing me from clicking on the left side of the link on this CSS flip card while using Chrome browser?

When attempting to click the left side of the link on the back of this flip card in Chrome, it does not respond. However, hovering over the right side allows interaction with the link: /* Vendor prefixed by https://autoprefixer.github.io */ .card { ...

utilize javascript to style iframe from an external domain without access to its DOM structure

I have two websites, example.com and example1.com. I'm trying to display the content of example1.com within an iframe on example.com. For instance: Add this code to example.com: <iframe src='http://example1.com'> Then add the follow ...

AngularJS call to the web service

I am facing an issue where I do not receive any response upon clicking the button. <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js"></script> <sc ...

Which SSO framework works best for integrating Facebook and Twitter logins?

I own a website and I'm looking for a way to let users leave reviews and rate products. I need an SSO system that allows them to sign in with their Facebook or Twitter accounts and ensures each user is uniquely identified so they can't rate produ ...

The art of arranging elements on a webpage using HTML and

I designed a rectangle using position: relative; and placed an icon inside it. However, when I added a new div class called .Home, and included an element <h4>Home</h4> with position: relative;, the element appeared outside of the rectangle. Wh ...

Ways to retrieve HTML content from various spans and incorporate the values as classes

Here is my custom HTML: <div class="box"> <ul class="fourcol first"> <li class="feature-item">Description: <span>0</span></li> <li class="feature-item">Description: <span>0</span></ ...

What could be causing the issue of Vuejs 3.3 defineModel consistently returning undefined?

I am currently working with Nuxt version 3.5.1 and Vuejs version 3.3, however, I am encountering an issue where the defineModel macro always returns undefined. I am unsure why this is happening? <template> <input v-model="count"& ...

How to Align Image and Overlay Div in Bootstrap 4

I'm trying to center an image and a div layer within a parent div, but I'm having trouble getting it to shift from the left side of the column. I've experimented with several methods, but nothing seems to work. Even using the margin auto tec ...

Utilizing ReactStrap: a guide to retrieving the id of the chosen dropDownItem

In my code, I have a dropdownList component with various DropdownItems: <Dropdown isOpen={this.state.dropdownOpen[3]} toggle={() => { this.toggle(3); }} > <DropdownToggle className="my-dropdown" car ...

Store the checked checkbox's value as 1

Is there a way to store the value of a checked checkbox as 1 and an unchecked checkbox as 0 while using boolean in my model? <div class="form-check form-check-inline"> <input name="vat" class="form-check-input" type="checkbox" id="inl ...

"Enhancing Code Readability with Language-Specific Syntax Highlighting

My goal is to develop an editor that allows users to input code in various languages by selecting an option from a dropdown menu. The code should then be automatically highlighted based on the chosen language. I am considering using Codemirror for syntax ...

Best practices for organizing your Obelisk project include creating a specific folder for CSS files within

Trying to align two divs side by side using Obelisk, I referred to this post for guidance on how to do it: How to place div side by side. The solution required declaring classes in CSS. Utilizing the instructions from a tutorial (https://github.com/hansrol ...

Create large rounded corners for the top half only in Bootstrap 4

Within Bootstrap 4, there are specific classes such as .rounded-top and .rounded-lg. My goal is to achieve a large rounded corner effect on only the top portion of an element. Applying the .rounded-top class successfully rounds the top as desired, but in o ...

At times, the Kendo UI Tooltip may linger on screen longer than expected, failing to disappear as

I've been experimenting with this issue for quite some time now, but I'm stumped. Whenever I quickly move my mouse cursor over a series of links, occasionally a tooltip will linger on the screen even after the cursor has moved away from the link. ...

I'm puzzled as to why the color isn't showing up on my navigation bar even though I used "padding: 10px !important;"

I really need help with this, I'm quite new to all of this and it's really confusing me. When I remove this line, the color shows up again, but when I add it back in, it just disappears. I've been following a tutorial on YouTube on how to cr ...

Why did the bootstrap installation in my project fail?

Previously, everything on my website was functioning correctly. However, upon launching it now, I noticed that the carousel, buttons, and other elements are broken. It seems like there might be an issue with the Bootstrap CDN as the buttons and sliders are ...