The functionality of aria-expanded is not functioning properly when set to false

Having trouble with the bootstrap accordion feature.
When the page loads, the accordions are expanded by default instead of being collapsed.
I want them to start collapsed and then expand when clicked.
Here is the HTML code:

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>bootstrap accordion</title>
  <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.css'><link rel="stylesheet" href="./style3.css">
  <link href="https://fonts.googleapis.com/css?family=Open+Sans&display=swap" rel="stylesheet"> 
  <link href="https://fonts.googleapis.com/css?family=Montserrat|Tomorrow&display=swap" rel="stylesheet"> 
</head>
<body>
<!-- partial:index.partial.html -->
<section class="container">
  <div id="accordion" class="accordion-container">
    <div class="card">
      <div class="card-header" id="headingOne">
        <h5 class="mb-0">
          <button id="radio" class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
          aaaa
          </button>
        </h5>
      </div>

      <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
        <div class="card-body">
         <p id="forward">aaaabooooody</p>
        </div>
      </div>
    </div>

      </div>

       <div id="accordion" class="accordion-container">
    <div class="card">
      <div class="card-header" id="headingOne">
        <h5 class="mb-0">
          <button id="radio" class="btn btn-link" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
          bbbbbbb
          </button>
        </h5>
      </div>

      <div id="collapseTwo" class="collapse show" aria-labelledby="headingTwo" data-parent="#accordion">
        <div class="card-body">
         <p id="forward">bbbbbbbbblaankkkk</p>
        </div>
      </div>
    </div>

      </div>



</section>
<!-- partial -->



  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/js/bootstrap.min.js'></script>
</body>
</html>


//////CSS CODE BELOW

.accordion-container .card .card-header button.btn:after {
  -webkit-transition: all 0.5s ease-in-out;
  -moz-transition: all 0.5s ease-in-out;
  -ms-transition: all 0.5s ease-in-out;
  transition: all 0.5s ease-in-out;
}
.accordion-container .card .card-header {
  position: relative;
  background-color: #00d2ff;
}
.accordion-container .card .card-header .btn-link {
  color: #FFF;
  font-family: 'Montserrat', sans-serif;
  font-size: 28px;
  /*font-weight: 600;*/
  line-height: 23px;
}
.accordion-container .card .card-header button.btn.collapsed:after {
  background-image: url();
}
.accordion-container .card .card-header button.btn:not(.collapsed):after {
  background-image: url();
}
.accordion-container .card .card-header button.btn-link {
  width: 100%;
  text-align: left;
}
.accordion-container .card .card-header button.btn:after {
  content: '';
  background-repeat: no-repeat;
  background-position: 50%;
  width: 3rem;
  height: 3rem;
  text-align: center;
  float: right;
  padding: .7rem;
  border: 1px solid #ffff;
  border-radius: 50%;
}
.accordion-container .card .card-header button.btn.collapsed:after {
  background-color: rgba(255, 255, 255, 0.31);
}
.accordion-container .card .card-header button.btn:not(.collapsed):after {
  background-color: white;
}
.accordion-container .card .card-header button.btn-link:not(.collapsed)::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: #FFF;
  opacity: .31;
}
.accordion-container .card .card-body {
  color: white;
  background-color:  #FFF;
  color: #000000;
  font-family: 'Open Sans', sans-serif;
  font-size: 18px;
  font-weight: 300;
  line-height: 19px;
}

This is what I expected on page load: https://i.stack.imgur.com/nPpSe.png
But this is what I'm seeing initially: https://i.stack.imgur.com/Mun1p.png

Answer №1

To make it function as intended, update the class="collapse show" to class="collapse".

Additionally, consider exploring this resource on the aria-expanded html attribute

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

Animate content to slide down using jQuery ajax once it has finished loading

Within my webpage, I have a grid of thumbnails that are each linked to their respective post pages. Upon clicking a thumbnail, a container div below smoothly slides down and loads the content using ajax. An issue has arisen: when I click on a thumbnail fo ...

By utilizing the body element as the container instead of a div, the content shifts to the left by eight pixels

When the body is used as the wrapper instead of a div, the content shifts eight pixels to the left (on a 1920×1080 display) when it extends below the fold. The examples below illustrate this difference in code snippets. Please note that the variance is on ...

Effortlessly lower several elements simultaneously with SlideDown

My form div contains multiple inner divs: <div class="form" style="display:none"> For example: <div class="row"> <?php echo $form->labelEx($model,'comment'); ?> <?php echo $form->textField($model,'commen ...

Steps to insert an image using ajax:

I am currently facing an issue while trying to include a form with an image field. I have successfully implemented the text field, but I am encountering difficulties with the image field. Upon using console.log, I noticed that my image is returning as unde ...

Sending JSON-encoded data using HTML5 Server-Sent Events (SSE) is a

I have a script that triggers an SSE event to fetch json encoded data from online.php. After some research, I discovered methods for sending JSON data via SSE by adding line breaks. My question is how to send JSON through SSE when the JSON array is genera ...

Should the max-height transition be set from 0 to automatically adjust or to none?

I'm dealing with an element that has a max-height of 0, and I want to smoothly transition it to either no max-height, auto, or none; essentially allowing it to expand based on the number of elements inside. I prefer not to use JavaScript or flex at th ...

What happens if setTimeout fails due to a page error?

My current setup involves using setTimeout to refresh the page, updating the jQuery template items. Here is a snippet of the relevant code: <script type="text/javascript"> var results = JSON.parse('@svgPath'.replace(/&quot;/g ...

Is it possible to make multiple AJAX requests at the same time using AngularJS

I am looking to simultaneously send multiple AJAX requests. Here is the JS code I have: <a class='btn btn-success' ng-click='getDataajax()'>Re Check</a> app.controller('customersCrtl', function($scope, $http, $ti ...

The background image on mobile devices is excessively zoomed in

My RWD page is experiencing a strange issue with the background image. The image has the following styles: #background-image { width: 100%; height: 100%; opacity: 0.5; position: absolute; z-index: -1; background-image: url('../landing.jpe ...

Change the CSS element if the current URL is not example.com/page1 or example.com/page2

When I apply the following JS code snippets, my output is incorrect or does not display at all. Below are the codes in question: if (location.href != "website.com/page1" || "website.com/page2") { element.style.backgroundColor='none'; ...

Link embedded within a list item

How can I make the hyperlink element fill up the width and height of the li element inside? <ul> <li><a href="#" style="display: block; width: 100%; height: 100%;">this link to fill up the li element width and height</a><l ...

The CSS styling of Vuetify TreeView does not support text wrapping

I'm having trouble getting the long text in this CodePen snippet to break and wrap properly. It extends off screen, rendering the append button unclickable. I've experimented with various CSS rules but haven't found a solution yet. Check ou ...

Collapse the Bootstrap Menu upon selecting a Link

I am working on a side menu with an offcanvas display feature. The current functionality is such that when the button is clicked, the canvas pushes left and opens the menu. However, I want the menu to collapse and close automatically when a link is selecte ...

Having trouble accessing the height of a div within an Iframe

Here is the issue I am facing: I need my iFrame to adjust its size based on a div within it, but every attempt to retrieve the size of this div results in 0. var childiFrame = document.getElementById("myDiv"); console.log(childiFra ...

Creating a CSS grid layout with dual columns to dynamically adjust and accommodate two items in each row

I am attempting to create this layout using CSS grid: The goal is to have an input and a textarea. The textarea should be of the size of 2 inputs. If there is already a textarea in the previous column, the next column should accommodate 2 inputs. The numb ...

What are some tips for managing the hover effect using CSS3?

Here's a demonstration of my current setup. When you hover over the black box, a transition occurs and reveals my tooltip. However, I only want the tooltip to appear when hovering over the black box itself. Currently, the transition also triggers if y ...

What could be causing my jQuery to malfunction after I include the .sqrt() function?

Seeking assistance in creating a grid of divs, I am working on finding the square root of the user's input to determine the height and width required to form a square. The code below is what I currently have: $('#size').click(function(){ $ ...

After an element has been hovered over for a duration of 500 milliseconds, execute a function using jQuery

To enhance the user experience, I am looking to trigger a 'mouseover' event only after half a second of hovering over the selector, rather than immediately. My first attempt involved using a setTimeout function, but it did not behave as expected ...

Display link based on checkbox selection using either Jquery or PHP

My website features a Document Request form where users can provide their basic information and select the specific documents they are interested in receiving. The form includes fields for Name, Email, and Documents Requested including Document 1, Documen ...

Building a dynamic webpage using AJAX, MVC, and web APIs to generate a div element filled

I'm currently working with a restful API, MVC, and ajax. My goal is to retrieve data from the backend and then display images within certain div elements. The expected outcome should resemble this example: https://i.stack.imgur.com/BFqWL.png This sni ...