Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<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>

<div class="wrapper">
<nav class="navbar navbar-light bg-light">
  <div class="container-fluid">
    <span class="navbar-brand mb-0 h1">Navbar</span>

<div class="tabs-holder">
  <ul class="nav nav-tabs nav-tabs-responsive" role="tablist">
    <li class="nav-item" role="tablist">
      <a class="nav-link active" id="tab-1" data-bs-toggle="tab" data-bs-target="#panel-1" type="button" role="tab" aria-controls="panel-1" aria-selected="true">
        Panel 1
      </a>
    </li>
    <li class="nav-item" role="tablist">
      <a class="nav-link" id="tab-2" data-bs-toggle="tab" data-bs-target="#panel-2" type="button" role="tab" aria-controls="panel-2" aria-selected="false">Panel 2 <strong>with html</strong></a>
    </li>
    <li class="nav-item" role="tablist">
      <a class="nav-link" id="tab-3" data-bs-toggle="tab" data-bs-target="#panel-3" type="button" role="tab" aria-controls="panel-3" aria-selected="false">Panel 3</a>
    </li>
    <li class="nav-item" role="tablist">
      <a class="nav-link disabled">Disabled<br>On two lines</a>
    </li>
    <li class="nav-item" role="tablist">
      <a class="nav-link disabled">A very long disabled tabs to see how it fits</a>
    </li>
   
  </ul>
</div>
  </div>
</nav>
  
<div class="tab-content">
  <div class="tab-pane fade show active" id="panel-1" role="tabpanel" aria-labelledby="tab-1">
    Panel 1. Try to resize this window or change the text of the tabs to see how it collapses into a dropdown.
  </div>
  <div class="tab-pane fade" id="panel-2" role="tabpanel" aria-labelledby="tab-2">
    Panel 2
  </div>
  <div class="tab-pane fade" id="panel-3" role="tabpanel" aria-labelledby="tab-3">
    Panel 3
  </div>
</div>
</div>
              
            
!

CSS

              
                .wrapper {
  margin: 2em;
  min-height: 600px;
}
.navbar {
  padding-bottom: 0 !important;
}
.tabs-holder .nav-tabs {
  border-bottom: 0;
  align-self: flex-end;
}
.nav-tabs li a {
  height: calc(100% + 1px);
}
.tab-content {
  padding: 1em;
}

/* This is our code */

.tabs-holder {
  flex-grow:1; /* we need the whole availble space */
}

.tabs-holder .nav-tabs {
  justify-content: flex-end;
}

.nav-tabs-dropdown a.active::after {
  display: inline-block;
  margin-left: 0.255em;
  vertical-align: 0.255em;
  content: "";
  border-top: 0.3em solid;
  border-right: 0.3em solid transparent;
  border-bottom: 0;
  border-left: 0.3em solid transparent;
}
.nav-tabs-dropdown a.active:empty::after {
  margin-left: 0;
}
.nav-tabs-dropdown a:not(.active) {
  display: none;
}

              
            
!

JS

              
                document.querySelectorAll(".nav-tabs-responsive").forEach((el) => {
  // Prevent multiple init from codepen
  if(el.dataset.responsiveTabs) {
    return;
  }
  el.dataset.ResponsiveTabs = true;
  // This only works if the nav is visible on page load
  let totalWidth = 0;
 
  el.querySelectorAll("li").forEach((tab) => {
    totalWidth += tab.offsetWidth;
  });
  el.style.visibility = "visible";
  el.dataset.tabsWidth = totalWidth;

  // Create mobile menu
  let menu = document.createElement("ul");
  menu.classList.add("dropdown-menu");
  el.querySelectorAll("a").forEach((link) => {
    let newChild = document.createElement("li");
    let newChildLink = document.createElement("a");
    newChild.append(newChildLink);
    newChildLink.classList.add("dropdown-item");
    newChildLink.innerHTML = link.innerHTML;
    if (link.classList.contains("disabled")) {
      newChildLink.classList.add("disabled");
    }
    // Forwards clicks to avoid binding stuff twice
    newChildLink.addEventListener("click", (ev) => {
      ev.preventDefault();
      link.dispatchEvent(new Event("click"));
    });
    menu.append(newChild);
  });
  el.parentElement.append(menu);

  // Register observer to trigger responsive layout
  
  const resizeObserver = new ResizeObserver((entries) => {
    for (let entry of entries) {
      const tabs = entry.target.querySelector(".nav-tabs-responsive");
      // check inlineSize (width) or blockSize (height)
      const contentBoxSize = Array.isArray(entry.contentBoxSize)
        ? entry.contentBoxSize[0]
        : entry.contentBoxSize;
      
      console.log(contentBoxSize);
      const size = contentBoxSize.inlineSize - 30;
      if (size < tabs.dataset.tabsWidth) {
        tabs.classList.add("nav-tabs-dropdown");
      } else if (size >= tabs.dataset.tabsWidth) {
        tabs.classList.remove("nav-tabs-dropdown");
        menu.style.display = "none";
      }
    }
  });
  
    console.log("attach observer");
  resizeObserver.observe(el.parentElement);

  // Handle responsive clicks
  el.querySelectorAll("a.nav-link").forEach((a) => {
    a.addEventListener("click", (ev) => {
      if (!a.classList.contains("active")) {
        return;
      }
      if (
        !a.parentElement.parentElement.classList.contains("nav-tabs-dropdown")
      ) {
        return;
      }
      // Toggle menu
      if (menu.style.display == "block") {
        menu.style.display = "none";
      } else {
        menu.style.display = "block";
        menu.style.right = "0px";
        menu.style.top = a.parentElement.offsetHeight + "px";
      }
    });
  });
});

              
            
!
999px

Console