css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="oddbirds">
  <input type="radio" name="toggle" id="eric-toggle" checked/>
  <input type="radio" name="toggle" id="carl-toggle" />
  <input type="radio" name="toggle" id="jonny-toggle" />
  
  <div class="tabs">
    <label for="eric-toggle">Eric</label>
    <label for="carl-toggle">Carl</label>
    <label for="jonny-toggle">Jonny</label>
  </div>
  
  <div class="content">
    <div class="eric-content">
      Responsive CSS Tabs in Sass, 
      with help from the float isolation method.
      <ul>
        <li>Container wraps all tabs dynamically</li>
        <li>Container remains equal-height</li>
        <li>No JS Height calculations</li>
        <li>The entire thing is responsive</li>
      </ul>  
    </div>
    <div class="carl-content">
      Carl is a coder, Pythonista, & Django developer.
    </div>
    <div class="jonny-content">
      Jonny is a front-end developer & philosophy professor.
      <ul>
        <li>Lorem ipsum dolor sit amet.</li>
        <li>Aliquam tincidunt mauris eu risus.</li>
        <li>Vestibulum auctor dapibus neque.</li>
        <li>Lorem ipsum dolor sit amet.</li>
        <li>Aliquam tincidunt mauris eu risus.</li>
        <li>Vestibulum auctor dapibus neque.</li>
      </ul>  
    </div>
  </div>
</div>
            
          
!
            
              @import "compass/css3";

@import "compass";

/* Tab Settings */
$default-checked-selector : ':checked';
$default-nested-selectors : null;

$toggle-attribute   : id;
$title-attribute    : for;
$content-attribute  : class;

/* Tab Toggle Defaults */
%gone {
  position: absolute;
  top: -9999px;
  left: -9999px;
}
%hide-tab-toggle { @extend %gone; }

/* Tab Content Defaults */
%hide-tab-content {
  @include transition(opacity 300ms);
  opacity: 0; /* Hide */
  float: left; /* Isolation */
  width: 100%; /* Isolation */
  margin-right: -100%; /* Isolation */
}
%show-tab-content {
  opacity: 1; /* Show */
  position: relative; /* Bring to top */
  z-index: 10; /* Bring to top */
}
%active-tab-title {
  background: none;
  border-bottom-color: rgba(black, 0);
}

/* Tabs Mixin */
@mixin tabs(
  $slugs,
  $nested: $default-nested-selectors,
  $checked: $default-checked-selector
) {
  $nested-tabs: $nested;
  $nested-content: $nested;
  @if length($nested) > 1 {
    $nested-tabs: nth($nested, 1);
    $nested-content: nth($nested, 2);
  }

  @each $slug in $slugs {
    $toggle   : '[#{$toggle-attribute}*="#{$slug}"]';
    $title    : '[#{$title-attribute}*="#{$slug}"]';
    $content  : '[#{$content-attribute}*="#{$slug}"]';

    #{$content} { @extend %hide-tab-content; }
    #{$toggle} {
      @extend %hide-tab-toggle;
      &#{$checked} {
        & ~ #{$nested-tabs} #{$title} {
          @extend %active-tab-title !optional;
        }
        & ~ #{$nested-content} #{$content} {
          @extend %show-tab-content;
        }
      }
    }
  }
}

/* Creating Tabs */
.oddbirds {
  @include tabs(eric carl jonny, ".tabs" ".content");
}

/* Paint Job */
* { @include box-sizing(border-box); }

body { 
  @include adjust-leading-to(1.1);
  padding: rhythm(1);
  background: #437691;
}

.oddbirds {
  @include box-shadow(rgba(black,.5) 0 0 .5em);
  width: 40%;
  max-width: 40em;
  margin: 0 auto;
  background: lightblue;
}

[for] {
  @include rhythm-borders(1px,.25);
  float: left;
  width: percentage(1/3);
  text-align: center;
  background: #7ac;
  ~ [for] { border-left: 0 }
  &:last-child { float: right; }
}

.content {
  @include clearfix;
  @include rhythm-borders(1px,.5);
  clear: both;
  border-top: 0;
  ul { 
    list-style: disc; 
    padding-left: rhythm(1);
  }
}

            
          
!
            
              // CSS-only tabs made easy with Sass.

// This demonstrates how I use the float isolation method, along with opacity and z-index, to create a responsive tab container. 

// - Container wraps all tabs dynamically
// - Container size remains equal across tabs
// - No JS height calculations
// - The entire thing is responsive

// You can use the `display` property instead if you want the container to change sizes depending on its content.

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console