cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              - var itemCount = 20;

.container
  p.description
    a(href='https://codepen.io/nksm/post/overflow-position-sticky') もう少しだけ追記した記事はこちら
  section
    header
      h1 親要素に特に何も指定しないブロック
    - for (var i = 0; i < itemCount ; i++) {
      .item
    - }
    footer
      p フッター
    
  section
    header
      h1 親要素に overflow を親要素に追加したブロック 
    - for (var i = 0; i < itemCount ; i++) {
      .item
    - }
    footer
      p フッター
            
          
!
            
              %header-and-footer {
  display: flex;
  align-items: center;
  min-height: 50px;
  padding: 10px;
  box-sizing: border-box;
  color: white;
}

.container {
  width: 300px;
}

.description {
  margin: 10px;
  padding: 10px;
}

section {
  margin: 10px;
  padding: 10px;
  background-color: darken(#fff, 2%);
  &:last-child {
    overflow: hidden;
  }
}

header {
  position: sticky;
  top: 0;
  background-color: tomato;
}

h1 {
  @extend %header-and-footer;
  margin: 0 0 10px;
  font-size: large;
}

footer {
  position: sticky;
  bottom: 0;
  background-color: darken(tomato, 30%);
  > p {
    @extend %header-and-footer;
    margin: 10px 0 0;
  }
}

.item {
  $border-color: #000;
  height: 30px;
  &:first-of-type {
    border-top: 1px solid $border-color;
  }
  &:last-of-type {
    border-bottom: 1px solid $border-color;
  }
  & + & {
    border-top: 1px dotted $border-color;
  }
}
            
          
!
999px
Loading ..................

Console