What is the best way to create a set of buttons that function like an accordion, displaying only one dropdown at a time?

Looking to design a user-friendly restaurant menu with categorized buttons that reveal information when clicked. The goal is to display one category at a time, so when a new button is pressed, the previous category disappears.

Struggling to find a solution for this functionality. Tried using an accordion layout, but it doesn't quite meet my needs.

Here's a snippet of what I have so far (menu details are incomplete):

<p>
   <div class="container"><div class="row justify-content-center">
    <a class="btn btn-primary mt-3 ml-1 mr-1" data-toggle="collapse" href="#omelet" role="button" aria-expanded="false" aria-controls="omelet">Omelets — Proven Favorites!</a>
    <button class="btn btn-primary mt-3 ml-1 mr-1" type="button" data-toggle="collapse" data-target="#favorites" aria-expanded="false" aria-controls="favorites">Favorites of Our Regulars</button>
    <button class="btn btn-primary mt-3 ml-1 mr-1" type="button" data-toggle="collapse" data-target="#eggCombo" aria-expanded="false" aria-controls="eggCombo">Egg Combinations</button>
  </div></div>
  </p>

  <div class="row">
    <div class="">
      <div class="collapse multi-collapse" id="omelet">
        <div class="card card-body">
            <div>
                <b>Cheese Omelet</b> — Choice of Jack, Cheddar, Swiss, Cream Cheese or Bleu Cheese
              </div>
              <div>
                <b>Turkey, Spinach, Onion, & Cheese Omelet</b><br>
              </div>
              <div>
                <b>Mushroom & Cheese Omelet</b>
              </div>
              <div>
                <b>Chili Cheese Omelet</b>
              </div>
              <div>
                <b>Veggie & Cheese Omelet</b> — Sautéed Mushrooms, Onions, Green Peppes, Zucchini, & Spinach
              </div>
              <div>
                <b>Avocado, Cream Cheese & Chive Omelet</b>
              </div>
              <div>
                <b>Mexican Cheese Omelet</b> — Chorizo, Mushrooms, Onions, Green Peppers, Zucchini, & Jack Cheese
              </div>
              <div>
                <b>Spinach, Mushroom & Cheese Omelet</b> — Hugh & Jean Special
              </div>
        </div>
      </div>
    </div>
    <div class="">
      <div class="collapse multi-collapse" id="favorites">
        <div class="card card-body">
          <b>André's Suggestions</b> — 1 biscuit & sausage gravy with 2 eggs & 2 strips of bacon; OR 1 biscuit & veggie gravy with extra veggies & fruit<br>
          <b>Whoopie's Breakfast</b> — 2 eggs any style, bacon, potatoes, toast, and large orange juice<br>
          <b>Nova's Favorite</b> — Spinach, eggs, and cheese scrumptiously scrambled and served with fruit, tortillas, small fresh squeezed O.J. and lots of salsa<br>
          <b>Bob's High Carbohydrate Runner's Breakfast</b> — 1 high protein pancake, 2 eggs any style, and potatoes<br>
          <b>Lily's Special</b> — Bowl of rice & cheese, small fruit plate, muffin<br>
          <b>Laura's Regular</b> — 1/2 raisin bread French toast, 2 strips of bacon, 1 egg<br>
          <b>Damian's Breakfast Burrito</b> — 2 eggs scrambled with salsa, avocado, and cheese, rolled in a tortilla, topped with sour cream and served with potatoes<br>
          <b>Dick's Diet Delight</b> — 2 eggs poached on an English muffin, seasonal fruit or small O.J.<br>
          <b>John's Special</b> — Granola with seasonal fruit and muffin; OR oatmeal with seasonal fruit and muffin<br>
        </div>
      </div>
    </div>
    <div class="">
        <div class="collapse multi-collapse" id="eggCombo">
          <div class="card card-body">
            <div>1 egg any style</div>
            <div>2 eggs any style</div>
            <div>2 eggs, 2 strips of Bacon</div>
            <div>2 eggs, 4 strips of bacon</div>
            <div>2 eggs, sausage</div>
            <div>2 eggs Ham <i>PJ's Fave</i></div>
            <div>2 eggs, turkey</div>
            <div>2 eggs, hamburger patty</div>
            <div>2 eggs, corned beef hash</div>
            <div>Huevos rancheros</div>
            <div>Rudy's Huevos Rancheros <i>Chorizo, beans, & green chilies</i></div>
          </div>
        </div>
      </div>
  </div>

In order to only display the last card associated with the button that was pressed, utilizing Bootstrap4, how can I make this work?

Answer №1

Toggleable Tabs offer a more tailored solution for your specific needs - you have the flexibility to customize the button color using #007bff, lightpink, or any other color of your choice. When you click on a tab, only the corresponding information is displayed while others remain hidden.

Check out the sample code snippet below:

.nav-item {
  background: lightgreen
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

<div class="container">
  <br>
  <!-- Nav tabs -->
  <ul class="nav nav-pills nav-justified" role="tablist">
    <li class="nav-item">
      <a class="nav-link active" data-toggle="pill" href="#home">Omelets — Proven Favorites</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" data-toggle="pill" href="#menu1">Favorites of Our Regulars</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" data-toggle="pill" href="#menu2">Egg Combinations</a>
    </li>
  </ul>

  <!-- Tab panes -->
  <div class="tab-content"> (truncated for brevity) 

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

Is it possible for CSS div to have a height of 100% when placed within fluid parents

When the parent div's height is set to 100%, you can also set the child to 100% and it will function correctly. However, if the parent's height is determined by its content, the height attribute does not work as expected. Are there any effective ...

"In the shadows, the .toLowerCase() method of undefined is failing without making a sound, yet the code

It seems that letting things fail in the background is necessary for this example to work consistently. Is there a way to work around this issue? There are instances where I need to check a div with a data-attribute on certain pages and add a class if it ...

Showing information from the data text option

I'm having trouble displaying text below the cube. The code works fine in a standalone fiddle, but it doesn't work when I incorporate it into my project. Can someone help me figure out how to show the value of data-text="Cube1"? Code t ...

Placing the date of each blog post at the end of the excerpt

Currently, there is a grid section on the homepage of our site showcasing the two most recent blog posts. I am looking for a Javascript solution to relocate the date to the bottom of each block, outside of the border. For reference, you can visit the follo ...

I attempted to utilize the <map> tag in creating a circular image that functions as a hyperlink, but unfortunately, it is not functioning correctly

I've been trying to create a round button using the code below, but something seems to be wrong with it. The issue I'm facing is that the area around the image is also clickable, even though I have used border-radius. Can someone please take a lo ...

I'm looking to increase a specific value by a set amount each time there is an input event triggered

I have created a range slider, but I am facing an issue with the oninput event. I want to increment a specific amount whenever the slider is adjusted. For example, I want to increase the amount by $150 when the slider is at $2000, and by $45000 for a parti ...

Is there a way for rainyday.js to utilize a CSS background image as its background?

I have a simple website with a fixed, full-sized background set using CSS. I am trying to incorporate rainyday.js to create a rain effect over the entire site, including the text. Currently, I am only able to get rainyday.js to display rain over a small s ...

Discovering the magic of Bootstrap 5 and mastering its classes

Currently facing an issue with the me and ms classes while learning to build a navbar. The requirement is for elements one and two to be left-aligned using the ms class, and elements three and four to be right-aligned using the me class. However, the eleme ...

Using the following-sibling selector in Java, you can easily click on all <li> elements within a <ul> tag

I am trying to navigate through the list of li elements starting from the "Mentorship" tag link <ul _ngcontent-cwp-c18="" class="navigation clearfix"> <li _ngcontent-cwp-c18="" routerlinkactive="current" ...

Building a dynamic 3-tier selection dropdown menu using an Input feature populated with JSON information

My goal is to create a dynamic dropdown selection group, where each selection depends on the previous one. I have tried the code below, and while I can populate the data for the first dropdown, the second and third dropdowns remain empty. I would greatly a ...

Tips for showcasing the button label on a different page upon clicking the button

I need help with a functionality where the name of a button clicked on one page is displayed on another page. Here's an example: <a href="#" class="btn btn-danger btn-lg btn-block"> <?php echo $sql->name; ?></a> Currently, echo ...

Obtain the URL of the parent window from a modal dialog using JavaScript

What is the proper syntax for obtaining the URL (specifically, the PATH) of the parent window from a modal dialog box in Internet Explorer. I have attempted several variations such as: window.opener.document.location window.opener.location this.opener.do ...

Generating dynamic dropdown menus and text content by extracting information from a database

Trying to wrap my head around dynamically generating elements on a page from a database and adding them to a table element. I know I can use jQuery for this, but I'm not sure if I should pre-build the data and show/hide it as needed. First, I have a ...

Expansive Carousel Feature with Ng Bootstrap

In my Angular 5 application, I am utilizing the Carousel component from "@ng-bootstrap/ng-bootstrap": "^1.1.2". I am trying to display pictures in full screen but when I press F11, the image appears like this. I am unsure of which CSS properties to apply ...

Show Pictures Tailored for Individual Users

My website is built using a combination of HTML, CSS, and a touch of JavaScript and jQuery. I've decided to go with MySql as my database. Currently, I have a login system in place where users can create their own accounts on the site. However, I&apo ...

Seeking assistance in developing a dynamic footer complete with a gallery of images

Attempting to create a footer packed with images but struggling to ensure it looks good on both PCs and mobile devices. The goal is to align the bronze sponsor kitten to the left, and supporter kittens to the right, while keeping the footer at a reasonabl ...

What is the best way to transfer a data string from my HTML document to my server (using either Node or Express) and trigger a specific function with that data?

Currently, my node.js server is operational and successfully creating an excel document by fetching data from an API using Axios. Now, I am looking to implement a feature where users can input a string on my HTML page, which will then be sent to the web se ...

Display Button and Div when Event occurs in Asp.net core using Razor Pages

I am currently working on a project that involves two dropdown menus: one for Categories and the other for SubCategories. Within a partial view named _CreateProject, I have set up an html form to facilitate the creation of new projects. My goal is to have ...

Flexbox presenting a specific alignment issue

I'm facing a challenge using Flexbox to achieve the desired result shown below https://i.sstatic.net/8vJGQ.png When trying to position my 2 blocks on the right, one of them ends up crossing the line and I struggle to bring it back up. I want this l ...

Transmit information to php script using an html document format

Is there a way to load the file table.php with the data that I am trying to pass when the ajax call is made? I have attempted to do this using the jquery.load method, where the second parameter is a data array, but it doesn't seem to be working. Here ...