0

I am very new here, and have spent some time learning HTML, CSS, and Bootstrap (5). As a starter project to practise these skills, I am attempting to replicate another website which includes (amongst other things), a tabbed section.

I followed a tutorial to create a tabbed section and have got all the content in each tab (two columns in each - one column with a picture and one column with a H3 and some text). However, when attempting to switch between tabs, the tabs won't switch.

The original tutorial was pretty minimal, and after it wouldn't work I tried searching on here and on Google. A few others suggested adding roles and aria controls to each div, which I tried but am still unsuccessful.

Please take a look and let me know what I have missed!

    <!DOCTYPE html>
<html lang="en-GB">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <Meta name="author" content="">
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
        
        <Meta name="description" content="">
        <title>Starbucks Tabs</title>

    </head>

    <body>

      <section id="favourites">
      
        <div class="container-fluid favourites-header">
          <h2 class="sectionheader">Get your favourites for free</h2>
        </div>

          <div class="container">
            <ul class="nav nav-tabs" role="tablist">
              <li class="nav-item"><a class="nav-link active" id="25link" data-bs-toggle="tab" role="tab" href="#25tab" aria-controls="25tab" aria-selected="true">25*</a></li>
              <li class="nav-item"><a class="nav-link" id="50link" data-bs-toggle="tab" role="tab" href="#50tab" aria-controls="50tab" aria-selected="false">50*</a></li>
              <li class="nav-item"><a class="nav-link" id="150link" data-bs-toggle="tab" role="tab" href="#150tab" aria-controls="150tab" aria-selected="false">150*</a></li>
              <li class="nav-item"><a class="nav-link" id="200link" data-bs-toggle="tab" role="tab" href="#200tab" aria-controls="200tab" aria-selected="false">200*</a></li>
              <li class="nav-item"><a class="nav-link" id="400link" data-bs-toggle="tab" role="tab" href="#400tab" aria-controls="400tab" aria-selected="false">400*</a></li>
            </ul>

            <div class="tab-content">

              <div class="tab-pane active show fade" role="tabpanel" id="25tab"  aria-labelledby="25link">
                <div class="row">
                  <div class="col">
                    <img src="img/025.png" alt="an espresso and a latte">
                  </div>
                  <div class="col">
                    <h3>Customise your drink</h3>
                    <p>Make your drink just right with an extra espresso shot, dairy substitute or a dash of your favorite syrup.</p>
                  </div>
                </div>
              </div>

              <div class="tab-pane fade" role="tabpanel" id="50tab" aria-labelledby="50link">
                <div class="row">
                  <div class="col">
                    <img src="img/050.png" alt="a cake and a black americano">
                  </div>
                  <div class="col">
                    <h3>Brewed hot coffee, bakery item, or hot tea</h3>
                    <p>Pair coffee cake or an almond croissant with your fresh cup of hot brew.</p>
                  </div>
                </div>
              </div>

              <div class="tab-pane fade" role="tabpanel" id="150tab" aria-labelledby="150link">
                <div class="row">
                  <div class="col">
                    <img src="img/150.png" alt="a muffin, a soda, and a caramel latte">
                  </div>
                  <div class="col">
                    <h3>Handcrafted drink, hot breakfast or parfait</h3>
                    <p>Have a really good morning with a breakfast sandwich, oatmeal or your favorite drink.</p>
                  </div>
                </div>
              </div>

              <div class="tab-pane fade" role="tabpanel" id="200tab" aria-labelledby="200link">
                <div class="row">
                  <div class="col">
                    <img src="img/200.png" alt="a chicken salad and a snack box">
                  </div>
                  <div class="col">
                    <h3>Salad, sandwich, or protein box</h3>
                    <p>Nourish your day with a hearty Chipotle Chicken Wrap or Eggs & Cheese Protein Box.</p>
                  </div>
                </div>
              </div>

              <div class="tab-pane fade" role="tabpanel" id="400tab" aria-labelledby="400link">
                <div class="row">
                  <div class="col">
                    <img src="img/400.png" alt="a mug and a bag of coffee">
                  </div>
                  <div class="col">
                    <h3>Select merchandise or at-home coffee</h3>
                    <p>Take home a signature cup, a bag of coffee or your choice of select coffee accessories.</p>
                  </div>
                </div>
              </div>


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

      <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>  
    </body>
</html>
jracland
  • 3
  • 3

1 Answers1

0

You have done everything correctly, except the id values. It should not begin with a number. You can read more about it here What are valid values for the id attribute in HTML?.

Coding Yaar
  • 86
  • 1
  • 6
  • Ahhh thank you so much. I renamed to, for example, #link25 and #tab25 and it works perfectly now. For future reference: Don't start element IDs with a number! – jracland Feb 13 '22 at 13:57