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="container-fluid">
  <div class="row">
    <div class="col-xs-8">
      <div class="dummy-contents">
        <!-- ページの高さを稼ぐために適当なダミーテキストを書き連ねておく -->
        <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>
    </div>
    <div class="col-xs-4">
      <ul class="affix-target nav nav-pills nav-stacked">
        <li class="active"><a href="#">Menu 1</a></li>
        <li><a href="#">Menu 2</a></li>
        <li><a href="#">Menu 3</a></li>
        <li><a href="#">Menu 4</a></li>
      </ul>
    </div>
  </div>
</div>

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

CSS

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

/* Affix を適用する対象の要素が position: fixed になった時の指定 */
.affix-target.affix {
  position: fixed !important;  /* .affix 自体に position: fixed 指定はあるものの、.affix-bottom が style 属性に position: relative を埋め込むので、それに勝るよう !important を指定しておく */
  top: 30px;  /* 画面上部からの位置を指定する。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

              
                $(() => {
  $('.affix-target').affix({
    offset: {
      top   : $('header').outerHeight(false),
      bottom: $('footer').outerHeight(true) + 400
    }
  })
    .on('affix.bs.affix', () => {
      // .affix-target の親要素の、padding の内側の幅を取得して、それを .affix-target の幅とする
      $('.affix-target').width($('.affix-target').parent().width());
    })
    .on('affix-top.bs.affix affix-bottom.bs.affix', () => {
      // .affix-top・.affix-bottom 時は上で指定した幅指定を解除し、親要素の幅に従わせる
      $('.affix-target').width('auto');
    });
  
  // ウィンドウリサイズに対応する
  $(window).resize(() => {
    // リサイズによる文章の折り返しなどでスクロール量が変わった場合に向けて、Affix の状況を再計算させる
    $('.affix-target').affix('checkPosition');
    // Affix 適用中の .affix-target のみ指定し、横幅を動的に設定する
    $('.affix-target.affix').width($('.affix-target').parent().width());
  });
});
              
            
!
999px

Console