Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <body onload="init();" />

<header id="header">
  <nav>
    <ul class="logo">
      <li>Logo</li>
    </ul>
    <ul class="menu-items">
      <li><a href="#tabstrip">Tab 1</a></li>
      <li><a href="#tabstrip">Tab 2</a></li>
      <li><a href="#tabstrip">Tab 3</a></li>
    </ul>
  </nav>
</header>

<section>
  <h2>
    Inspired by an interesting requirement posted in the <a href="https://theme-fusion.com/forums/topic/anchor-links-to-fusion-tabs-on-same-page/">Avada forum</a>
  </h2>
  <p>The menu items above will scroll to a set of tabs further below and open the selected tab. Kinda like a remote control tab set. Give it a try by cliking on one or all of the <em>Tab</em> links above.</p>
  <p>Each tab contains tips and tricks to make this work in Avada.</p>
  <hr>
  <p>Hashtag eu roof party magna heirloom craft beer, aesthetic tacos direct trade hoodie in et beard. Snackwave ennui YOLO beard ethical tattooed. Retro laborum food truck photo booth. Hella shabby chic coloring book glossier tempor tbh pork belly succulents taxidermy mixtape fingerstache raclette anim austin. Intelligentsia ennui tousled, mustache taxidermy raclette jianbing distillery. Butcher la croix incididunt exercitation veniam.</p>

  <p>Adaptogen pabst incididunt, flexitarian ut veniam pop-up selfies everyday carry ennui lo-fi keytar est gluten-free celiac. Meggings la croix food truck culpa pop-up austin succulents wolf. Hella succulents kitsch taiyaki. Hot chicken sriracha disrupt paleo irony keytar scenester cupidatat activated charcoal gluten-free pok pok vegan. Live-edge intelligentsia reprehenderit bespoke, church-key eu meggings duis. Mlkshk locavore ut dolor.</p>

  <p>Meditation deserunt bespoke, typewriter ennui 3 wolf moon venmo migas austin aliqua. Lorem cloud bread succulents seitan ea est commodo af bitters. Wolf hot chicken laboris waistcoat umami. You probably haven't heard of them before they sold out fixie selfies pariatur synth tumeric migas raw denim. Sartorial mustache literally, freegan cliche iceland pop-up raclette biodiesel sriracha portland. Flannel ethical edison bulb, cardigan normcore unicorn portland kinfolk enim cronut williamsburg. Cillum master cleanse forage eiusmod, fingerstache sint put a bird on it tousled literally.</p>
</section>

<div id="tabstrip">
  <span id="tab1"><i class="fontawesome-icon fa-laptop fas" style="font-size:16px;"></i>Tab 1</span>
  <span id="tab2"><i class="fontawesome-icon fa-rocket fas" style="font-size:16px;"></i>Tab 2</span>
  <span id="tab3"><i class="fontawesome-icon fa-code fas" style="font-size:16px;"></i>Tab 3</span>
  <div>
    <p>Notice that I'm not hidden when you get to me from my top menu link. Yes, the sticky header above is respected in this demo.</p>
    <p>Scroll back to the top and click on <em>Tab 2</em> to see this in action again.</p>
    <hr>
    Consequat trust fund narwhal beard gochujang neutra id, sint pabst taxidermy pitchfork. Tempor ipsum bicycle rights, ut artisan poutine viral small batch slow-carb kitsch freegan cred dreamcatcher direct trade id. Celiac VHS mustache squid schlitz. Lomo vape aliquip intelligentsia. La croix four loko keffiyeh deep v fashion axe laborum retro gluten-free pickled 3 wolf moon mumblecore quis ex. Kinfolk poke sed, portland cred succulents shaman wayfarers laboris tbh before they sold out live-edge.
  </div>
  <div>
    <p>If you want to make this work in your Avada site, you can try the following:</p>
    <ol class="body-list">
      <li>Copy/paste this HTML as a template into a Fusion Builder <em>code element.</em></li>
      <li>Remove the body and header sections.</li>
      <li>Change the tab headings and body contents to what you want.</li>
      <li>Add or remove spans (tab headings) and divs (tab contents) as needed.</li>
      <li>Copy/paste the CSS into your page's CSS setting. Keep the very first rule and all the tab related rules. Remove what's not needed e.g., body and to-top classes.</li>
      <li>Click on Tab 3 for the JavaScript part.</li>
    </ol>
    <hr>
    Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by
    their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic
    life One day however a small line of blind text by the name of Lorem Ipsum decided to
  </div>
  <div>
     <p>For the JavaScript, you can try the following:</p>
    <ol class="body-list">
      <li>Copy/paste the JavaScript into the Avada > Theme Options > Advanced > Code Fields > Space before &lt;/body&gt;. See this <a href="https://theme-fusion.com/wp-content/uploads/2018/05/doc_6.2_fusion_theme_options_advanced_code_fields.jpg">graphic</a> for more info.</li>
  <li>Remove all the <em>To Top</em> code.</li>
      <li>Add this line to the very bottom of the code: <mark>init();</mark></li>
      <li>Enclose the entire JavaScript in <em>script</em> tags.</li>
    </ol>
    <hr>
    The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog. Junk MTV quiz graced by fox whelps. Bawds jog, flick quartz, vex nymphs. Waltz, bad nymph, for quick jigs vex! Fox nymphs grab quick-jived waltz. Brick quiz whangs jumpy veldt
    fox. Bright vixens jump; dozy fowl quack. Quick wafting zephyrs vex bold Jim. Quick zephyrs blow, vexing daft Jim. Sex-charged fop blew my junk TV quiz. How quickly daft jumping zebras vex. Two driven jocks help fax my big quiz. Quick, Baz, get
    my woven flax jodhpurs! "Now fax quiz Jack! " my brave
  </div>
</div>

<section>
  <p>Hashtag eu roof party magna heirloom craft beer, aesthetic tacos direct trade hoodie in et beard. Snackwave ennui YOLO beard ethical tattooed. Retro laborum food truck photo booth. Hella shabby chic coloring book glossier tempor tbh pork belly succulents taxidermy mixtape fingerstache raclette anim austin. Intelligentsia ennui tousled, mustache taxidermy raclette jianbing distillery. Butcher la croix incididunt exercitation veniam.</p>

  <p>Adaptogen pabst incididunt, flexitarian ut veniam pop-up selfies everyday carry ennui lo-fi keytar est gluten-free celiac. Meggings la croix food truck culpa pop-up austin succulents wolf. Hella succulents kitsch taiyaki. Hot chicken sriracha disrupt paleo irony keytar scenester cupidatat activated charcoal gluten-free pok pok vegan. Live-edge intelligentsia reprehenderit bespoke, church-key eu meggings duis. Mlkshk locavore ut dolor.</p>

  <p>Meditation deserunt bespoke, typewriter ennui 3 wolf moon venmo migas austin aliqua. Lorem cloud bread succulents seitan ea est commodo af bitters. Wolf hot chicken laboris waistcoat umami. You probably haven't heard of them before they sold out fixie selfies pariatur synth tumeric migas raw denim. Sartorial mustache literally, freegan cliche iceland pop-up raclette biodiesel sriracha portland. Flannel ethical edison bulb, cardigan normcore unicorn portland kinfolk enim cronut williamsburg. Cillum master cleanse forage eiusmod, fingerstache sint put a bird on it tousled literally.</p>
</section>

<button onclick="topFunction()" id="toTopBut" title="Go to top">&#8593;</button>
</body>
              
            
!

CSS

              
                /** 
 * CSS trick for avoiding header overlapping
 * content for menu anchors.
 *
 * From Adrian Garner on Stack Overflow 
 *
 * https://stackoverflow.com/questions/4086107/fixed-page-header-overlaps-in-page-anchors 
 */
:target::before {
    content: "";
    display: block;
    height: 6rem; /* Fixed header height for this page. */
    margin: -6rem 0 0; /* To compensate for a huge space at the top. */
}

/** General CSS */

body {
  font-family: Helvetica, Arial, sans-serif;
  font-weight: 300;
  font-size: 18px;
  line-height: 1.5;
  color: whitesmoke; /* #24292e; */
  background-color: slategray;
  padding: 1% 5%;
  margin: 0;
}

a {
  color: whitesmoke;
  text-decoration: none;
}

section a {
  color: white;
  text-decoration: none;
  border-bottom: 2px solid white;
}

section a:hover {
  opacity: 80%;
}

i {
  padding-right: 10px;
}

header {
  display: box;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  margin: 0;
  height: 5rem;
  z-index: 10;
  background-color: #212326;
  min-width: 300px;
  overflow-y: scroll;
  font-size: 20px;
  color: #efefef;
  overflow: hidden;
}

nav {
  padding: 1% 0;  
}

header ul {
  display: inline-block;
  list-style: none;
}

.menu-items {
  position: absolute;
  right: 2rem;
}

li {
  display: inline-block;
}

.menu-items li {
  margin-left: 4rem;
  cursor: pointer;
}

.menu-items li:hover {
  border-bottom: 2px solid white;
}

/** Tab Stuff */

#tabstrip {
  display: block;
  margin-top: 5rem; /* Offset for sticky header. */
  padding: 0em;
  width: 75%;
}

.tab {
  font-weight: 400;
  cursor: pointer;
  float: left;
  margin: 0 0.2em 0 0;
  min-width: 3em;
  overflow: hidden;
  padding: 0.625em;
  white-space: nowrap;
  color: #111;
}

.body-list li {
  margin-bottom: .8em;
}

section {
  margin: 5rem auto;  
}

.activeTab {
  background-color: darkgray;
}

.inactiveTab {
  background-color: dimgray;
}

.activePanel {
  color: #111;
  background-color: darkgray;
  clear: both;
  display: block;
  padding: 1em;
}

.inactivePanel {
  display: none;
}

/** To Top Stuff */

#toTopBut {
  display: none; /* Hidden by default */
  position: fixed; /* Fixed/sticky position */
  bottom: 20px; /* Place the button at the bottom of the page */
  right: 30px; /* Place the button 30px from the right */
  z-index: 99; /* Make sure it does not overlap */
  border: none; /* Remove borders */
  outline: none; /* Remove outline */
  background-color: rgba(0,0,0,0.5); /* Set a background color */
  color: white; /* Text color */
  cursor: pointer; /* Add a mouse pointer on hover */
  padding: 15px; /* Some padding */
  border-radius: 10px; /* Rounded corners */
  font-size: 1.5em; /* Increase font size */
}

#toTopBut:hover {
  background-color: #555; /* Add a dark-grey background on hover */
}

              
            
!

JS

              
                "use strict";

/** Globals */

let tabs = document.querySelectorAll("#tabstrip > span"),
  panels = document.querySelectorAll("#tabstrip > div"),
  length = tabs.length,
  currentTab,
  currentPanel;

// To Top Global
let toTopButton = document.getElementById("toTopBut");

/** End Globals */

/** Tab Stuff */

function getToggler(newTab, newPanel) {
  return function () {
    currentTab.className = "tab inactiveTab";
    currentPanel.className = "inactivePanel";
    newTab.className = "tab activeTab";
    newPanel.className = "activePanel";
    currentTab = newTab;
    currentPanel = newPanel;
  };
}

/** End Tab Stuff */

/** To Top Stuff */

function toTop() {
  window.scroll({
    top: 0,
    left: 0,
    behavior: "smooth"
  });
}

// When we scroll down 20px from the top of the document, show the button
window.onscroll = function () {
  scrollFunction();
};

function scrollFunction() {
  if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
    toTopButton.style.display = "block";
  } else {
    toTopButton.style.display = "none";
  }
}

// When we click on the button, scroll to the top of the document
function topFunction() {
  window.scroll({
    top: 0,
    left: 0,
    behavior: "smooth"
  });
}

/** End To Top Stuff */

/** Main */

function init() {
  if (length === 0) {
    console.log("No tabs here.");
    return;
  }
  
  console.log("Found " + length + " tabs.");
    
  let menuItems = document.querySelectorAll(".menu-items > li");

  if (length !== panels.length)
    throw new Error(
      "Number of tabs (" +
        length +
        ") and number of content panels (" +
        panels.length +
        ") are not equal"
    );

  for (let i = 0; i < length; i++) {
    let tab = tabs[i];
    let panel = panels[i];
    let menuItem = menuItems[i];

    tab.className = "tab inactiveTab";
    tab.addEventListener("click", getToggler(tab, panel), false);
    menuItem.addEventListener("click", getToggler(tab, panel), false);
    panel.className = "inactivePanel";
  }

  currentTab = tabs[0];
  currentPanel = panels[0];
  currentTab.className = "tab activeTab";
  currentPanel.className = "activePanel";
}

              
            
!
999px

Console