Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
img {
  width: 100%;
  height: auto;
}




  <div>
       <ul class="nav nav-tabs">
         <li>              <a href="#Home" class="nav-link active" data-toggle="tab">Home</a>
       </li>    <li>              <a href="#News" class="nav-link" data-toggle="tab">News</a>
       </li>    <li>              <a href="#Contact" data-toggle="tab">Contact</a>
       </li>    <li style="float: right">              <a href="#About" class="nav-link" data-toggle="tab">About</a>
      </li>  </ul>

  <div class="tab-content">
    <div class="tab-pane active" id="Home">
      heloo
    </div>
    <div class="tab-pane" id="News">
      gggg
    </div>
    <div class="tab-pane" id="Contact">
      gggg
    </div>
    <div class="tab-pane" id="About">
      hghhg
           </div>
        </div>
     </div>


What I have tried:

it shows all the values on 1 class,even if i click on news or contact,it still shows 4 values instead of 1



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="scrollbar.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<img src="forest1.jpg" alt="forest" width="1350" height="250">
<style>
img {
  width: 100%;
  height: auto;
}

</style>
</head>
<body>
  <div role="tabpanel">
       <ul class="nav nav-tabs" role="tablist">
         <li role="nav-item">
              <a href="#Home" class="nav-link active" aria-controls="Home" data-toggle="tab">Home</a>
       </li>
    <li  role="nav-item">
              <a href="#News" class="nav-link" aria controls="News" data-toggle="tab">News</a>
       </li>
    <li role="nav-item">
              <a href="#Contact" classs="nav-link"  aria controls="Contact" data-toggle="tab">Contact</a>
       </li>
    <li style="float:right" role="nav-item">
              <a href="#About" class="nav-link" aria controls="About" data-toggle="tab">About</a>
      </li>
  </ul>

  <div class="tab-content">
    <div role="tabpanel" class="tab-pane active" id="Home">
      heloo
    </div>
    <div role="tabpanel" class="tab-pane" id="News">
      gggg
    </div>
    <div role="tabpanel" class="tab-pane" id="Contact">
      gggg
    </div>
    <div role="tabpanel" class="tab-pane" id="About">
      hghhg
           </div>
        </div>
     </div>
  </div>


 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
 <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css"></script>
</body>
</html>
Posted
Updated 4-Jul-21 22:26pm
v3

1 solution

You are importing the Bootstrap 4.5.3 Javascript, but the Bootstrap 4.0 Beta 3 CSS.

Don't mix and match versions; import the same version of the CSS and Javascript.
HTML
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
Introduction · Bootstrap v4.5[^]

With the correct versions in place, your tabs work as expected: Demo[^]

You have some issues - an extra "s" on the contact tab's "class"; using role="nav-item" instead of class="nav-item"; using aria controls instead of aria-controls. Fixing those makes the contact tab align properly: Updated demo[^]

NB: Using float in the tab list doesn't work. You can see that the floated tab still appears in the same place. If you want it aligned to the right, you should add class="ml-auto" instead: Final demo[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900