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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                <!-- Tabs -->
<nav>
  <ul class="tab">
    <li data-solution="1" class="active">Solution 1</li>
    <li data-solution="2">Solution 2</li>
  </ul>
</nav>

<!-- Tab Content: Solutions -->
<div class="solution active" id="solution1">
  <div class="note">
    <p>Using a completely colored background for a pseudo element (<code>::before</code>) that is covered by the main
      element which has a dashed border the same color as its background.</p>
    <p>And the key is <code>background-clip</code>.</p>
  </div>

  <div class="wrapper solutionOne">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent bibendum, lorem vel tincidunt imperdiet, nibh
      elit laoreet felis, a bibendum nisl tortor non orci. Donec pretium fermentum felis, quis aliquet est rutrum ut.
      Integer quis massa ut lacus viverra pharetra in eu lacus. Aliquam tempus odio adipiscing diam pellentesque
      rhoncus. Curabitur a bibendum est.</p>
  </div>
</div>

<div class="solution" id="solution2">
  <div class="note">
    <p>This solution is only <code>background</code>.</p>
    <p>It's surprising that something so complicated can be so simple... And how powerful CSS(3) has became!</p>
  </div>

  <div class="wrapper solutionTwo">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent bibendum, lorem vel tincidunt imperdiet, nibh
      elit laoreet felis, a bibendum nisl tortor non orci. Donec pretium fermentum felis, quis aliquet est rutrum ut.
      Integer quis massa ut lacus viverra pharetra in eu lacus. Aliquam tempus odio adipiscing diam pellentesque
      rhoncus. Curabitur a bibendum est.</p>
  </div>
</div>
              
            
!

CSS

              
                :root {
  --colorTextMain: hsl(211.6, 8.2%, 45.7%);
  --colorGrey: hsl(0, 0%, 85.9%);
  --colorRed: hsl(347.8, 86.3%, 45.9%);
  --colorBlue: hsl(228.7, 53.1%, 46.9%);
  --colorBlueLighter: hsl(229.1, 53.1%, 53.1%);
  --colorLightGrey: hsl(200, 42.9%, 97.3%);
  --colorLightYellow: hsl(60,37.9%,94.3%);

  --colorfulGradient: linear-gradient(
    to bottom,
    hsl(39.5, 99.2%, 52.5%),
    hsl(349, 68.9%, 53.3%) 70%
  );
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  color: var(--colorTextMain);
  font-family: BlinkMacSystemFont, -apple-system, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Helvetica,
    Arial, sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  line-height: 1.5;
}

/* Tabs
 ================================ */

.tab {
  list-style: none;
  border-bottom: 1px solid var(--colorGrey);
  font-size: 1.5rem;
  padding: 0 1rem;
}

.tab li {
  display: inline-block;
  padding: 0.5em 1em;
  margin-bottom: -1px;
  border-bottom: 1px solid transparent;
  cursor: pointer;
}

.tab li.active {
  color: var(--colorBlue);
  border-color: var(--colorBlueLighter);
}

/* Solutions
 ================================ */

.solution {
  max-width: 500px;
  display: none;
}
.solution.active {
  display: block;
}

.note {
  background-color: var(--colorLightGrey);
  color: var(--colorBlue);
  padding: 1.25em 1.5em;
  border-radius: 0.375em;
  border-left: 4px solid var(--colorBlueLighter);
  margin-bottom: 2rem;
}
.note code {
  background-color: var(--colorLightYellow);
  color: var(--colorRed);
  font-weight: 400;
  padding: 0.25em 0.5em 0.25em;
}

.wrapper {
  background-color: var(--colorLightGrey);
  max-width: 500px;
  padding: 1.5rem;
  border-radius: 1rem;
}

/* Solution 1 */
.solutionOne {
  position: relative;
  background-clip: padding-box;
  border: 1px dashed var(--colorLightGrey);
}

.solutionOne::before {
  position: absolute;
  z-index: -1;
  content: "";
  inset: 0;
  margin: -1px;
  border-radius: inherit;
  background: var(--colorfulGradient);
}

/* Solution 2 */
.solutionTwo {
  border: 1px dashed var(--colorLightGrey);
  background: linear-gradient(var(--colorLightGrey), var(--colorLightGrey))
      padding-box,
    var(--colorfulGradient) border-box;
}

              
            
!

JS

              
                const tabItems = document.querySelectorAll(".tab li");
const solutions = document.querySelectorAll(".solution");

const removeClass = (item, className) => {
  item.classList.remove(className);
};

const removeActive = () => {
  tabItems.forEach((item) => removeClass(item, "active"));

  solutions.forEach((item) => removeClass(item, "active"));
};

const openSolution = (num) => {
  const id = `solution${num}`;
  const solution = document.getElementById(id);
  solution.classList.add("active");
};

tabItems.forEach((item) => {
  item.addEventListener("click", function () {
    removeActive();
    this.classList.toggle("active");
    openSolution(this.dataset.solution);
  });
});

              
            
!
999px

Console