Tips for customizing the CSS Accordion to support multiple instances on one page

Hi there, I came across an accordion on a website: designed by the talented Paul Underwood. I really like this accordion because of its sleek design achieved with simple CSS. However, I have encountered an issue where I want to include multiple accordions on the same page. This creates a problem as they all share the same class, impacting their functionality. Is there a way to give each accordion its own unique class without having to manually copy, paste, and rename everything? My ultimate goal is to have several accordions working together on a single page.

Below is the code from the original website:

Html:

 <div class="accordion vertical">  
 <section>  
      <h2>About Us</h2>  
      <p>Lorem ipsum dolor sit amet,</p>  
  </section>  

<section>  
    <h2>Services</h2>  
    <p>Lorem ipsum dolor sit amet,</p>  
</section>  

<section>  
    <h2>Blog</h2>  
    <p>Lorem ipsum dolor sit amet</p>  
</section>  

<section>  
    <h2>Portfolio</h2>  
    <p>Lorem ipsum dolor sit amet,</p>  
</section>  

<section>  
    <h2>Contact</h2>  
    <p>Lorem ipsum dolor sit amet</p>  
</section>  
</div>  

CSS:

/**
 *  CSS3 Only Horizontal and Vertical Accordion
 *  Author: Paul Underwood for Hongkiat.com
 *  Website: www.paulund.co.uk
 *  Date: 27/11/11
 *  Version: 1.0
 */

//CSS code not altered

Answer №1

No need to make any CSS adjustments. Simply modify the ids and targets in the HTML code for a new table, like so:

    <div class="accordion vertical">
      <section id="bar">
          <h2><a href="#bar">Bar</a></h2>
          <!-- content -->
          <p>lorem ipsum dolor sit amet</p>
      </section>
    </div>

and so on...

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

The Ultimate Slider: Highlighting Custom Navigation Link as Active While Navigating with Arrows

I have implemented custom navigation links for my slick slider in order to navigate to specific slides. The functionality works perfectly, but I encountered an issue when I added the built-in arrows provided by the slider. Whenever I use these arrows to n ...

Having difficulty uploading files to my website [PHP]

I'm having trouble with a PHP tutorial I followed for uploading an image. Despite my best efforts, the upload always fails and I can't figure out why. I've rewritten the code multiple times but the problem persists. The goal of this code is ...

Angular 6 is showcasing dates in a quirky manner

In my Angular app, users can enter comments. The comments are displayed automatically with the date they were added. However, there is an odd behavior that I've noticed: When a user enters a comment, the time displayed is incorrect. (Check the ...

Troubleshooting the issues with implementing cross-browser jscrollpane functionality

Hey there! I've been exploring this tool to customize the default scroll-bar, and here's a fiddle showcasing my experimentation. In the fiddle, I've included the following code snippet <div class="scroll-pane horizontal-only">(located ...

Utilizing jQuery for real-time operations

I am working with two input text fields and I am looking to utilize jQuery to perform an operation between them. Here are the input text fields: <p> <label>Title 1</label> <span class="field"> <input type="text" ...

Unleash the power of attribute selectors in a SASS/SCSS list variable: a comprehensive guide!

This is a sample code snippet: $list: ( input[type="text"], input[type="name"], input[type="email"], textarea, select[multiple] ) !default; @each $value in $list { ...

What is the correct way to create a card outline in Bootstrap?

I am currently developing a Django website to enhance my skills in coding, CSS, Html, and Bootstrap. However, I am encountering an issue with the main page of my site. The visuals on my cards do not align properly with the colored boxes at the top of the p ...

What causes the gap between a parent div and inner div in react components?

I have a relatively simple React component that I'm working on. Even though I am quite new to React, I have tried various methods to eliminate the white space issue but so far have been unsuccessful in determining what is causing it. Negative margin s ...

a div sandwiched between two others

I am trying to nest a <div> within another <div> and center it within the parent. Here is my current approach: <div id="redthing"> <div id="whitebox" > </div> </div> The CSS code I am using is as follows: #red ...

Arrange the div and ensure that the external JavaScript file functions properly when the page loads

I am encountering an issue with my JavaScript and CSS code. It works perfectly fine within the fiddle environment but fails to function properly outside of it. Here is the link to the fiddle When I embed the code into an HTML document directly, it does n ...

Incorporating various elements within a single column of a table

I have been attempting to include multiple table cells elements beneath each of my heading cells, but I am facing issues in getting it to work properly. For better understanding, this is a screenshot: https://i.sstatic.net/kg2XR.png My goal is to have o ...

"The position of the Textbox shifts suddenly following the input of text

One interesting quirk I've noticed in my HTML code is that a text box with a jQuery button attached to it seems to shift down by about 4 pixels when the user enters text and then moves away from the box using the tab key or mouse. <div class=&apos ...

Looking to have the image float after reducing the size of the windows in html?

For my webpage, I want an image to appear on the extreme left when the browser is maximized, but then move to the extreme right when the browser is minimized. I've tried using float, but it doesn't seem to be working. Any suggestions on how to ac ...

Running JavaScript code along with HTML elements extracted from a jQuery ajax callback

Alternatively, not exactly "executing," but rather updating a pre-existing function with a function returned in the response. Step 1 I have an HTML5 page detailing a specific location. The server-side includes a ColdFusion file called "MapFunction.cfm" ...

Tips for updating the color of a table row when it is chosen and a row is inserted using ajax

I have successfully added table rows dynamically through ajax in MVC C#. Now, I am looking to change the color of a selected row. This effect works well on the table with rows generated in the HTML view. <div class="col-lg-6 col-sm-12"> ...

The script functions perfectly on one page, but encounters issues on another page

I'm currently working on developing an iOS7 WebApp using a template that I came across on this website: After writing some JavaScript/jQuery to create a fading effect for a picture and a toolbar, and testing it successfully on a blank page, I encount ...

How to perfectly position an image within a fixed full screen container

When you click on a thumbnail image, a full-screen overlay with a larger version of the image will be triggered using JavaScript. To ensure that the image is centered and resized inside the black overlay when the browser window size changes, I attempted t ...

What is the process of inserting a placeholder in an ng-repeat dropdown input field?

I have a situation where I need to implement a drop-down using ng-repeat. The challenge is that I want to include a placeholder in the input box so that it doesn't remain blank when no option is selected from the drop-down. Setting a default placehold ...

The image displays successfully on desktop, however, it fails to load once the website is deployed on GitHub or Netlify

While developing this website on my Mac, I encountered an issue where images load fine when I copy the project path from Atom to Chrome. However, once I push the same code to GitHub and then publish it on Netlify, the image fails to load. Does anyone kno ...

What is the best way to end a column early using a media query?

I need some help with adjusting the card layout in my project. I want the cards to break at a specific window size of 700px, but it's not working as expected. Can anyone provide guidance on how to achieve this? Thank you in advance for your assistance ...