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

              
                <header style="height: 250px; margin-bottom: 30px; color: #fff; background: #08f;">HEADER</header>

<div class="affix-target-wrapper">
  <!--
    offset-top    : 280 (px) = header 要素の height (250px) + margin-bottom (30px)
    offset-bottom : 今回は適当に、画面最下部から 600px のところで解除する
  -->
  <div class="affix-target btn-group btn-group-justified" data-spy="affix" data-offset-top="280" data-offset-bottom="600">
    <a href="#" class="btn btn-default">Menu 1</a>
    <a href="#" class="btn btn-default">Menu 2</a>
    <a href="#" class="btn btn-default">Menu 3</a>
  </div>
</div>

<div class="dummy-contents" style="max-width: 800px;">
  <!-- ページの高さを稼ぐために適当なダミーテキストを書き連ねておく -->
  <p>Author : <a href="http://neo.s21.xrea.com/">Neo</a></p>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>

<footer style="height: 500px; color: #fff; background: #444;">FOOTER</footer>
              
            
!

CSS

              
                /* 子要素 .affix-target が position: fixed になった時、その下にあるコンテンツの表示位置がズレないよう指定しておく */
.affix-target-wrapper {
  height: 60px;
}

/* Affix を適用する対象の要素 */
.affix-target {
  width: 500px;    /* position: fixed になった時、幅が狂わないよう指定しておく */
  z-index: 99999;  /* position: fixed になった時、他の要素の下に重ならないようにしておく */
}

/* Affix を適用する対象の要素が position: fixed になった時の指定 */
.affix-target.affix {
  position: fixed !important;  /* .affix 自体に position: fixed 指定はあるものの、.affix-bottom が style 属性に position: relative を埋め込むので、それに勝るよう !important を指定しておく */
  top: 0;  /* 画面上部からの位置を指定する。data-offset-top との辻褄が合う数値にしておくこと */
}



/* Affix の適用状態に応じて文字色を変える */
.affix-top    * { color: blue;  }  /* Affix 開始よりスクロール位置が上の場合 */
.affix        * { color: red;   }  /* position: fixed になった時 */
.affix-bottom * { color: green; }  /* Affix を解除するスクロール位置より下の場合 */

/* ページの高さを稼ぐためのコード */
.dummy-contents p {
  line-height: 3;
  margin-bottom: 3rem;
}
              
            
!

JS

              
                
              
            
!
999px

Console