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

              
                <div class="wrapper">
      <div class="box1"></div>
      <article>
        <p>
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Eveniet esse
          voluptates quibusdam qui unde. Totam nulla cupiditate expedita esse
          quam magni dolores, odit minima consequatur pariatur quidem culpa,
          necessitatibus saepe autem labore at ex sed. Aliquid odit expedita,
          dolorem neque rerum nihil a omnis cum praesentium quos impedit esse
          magnam, sequi earum laudantium repellat pariatur laboriosam hic dolore
          eos tempora quis eum! Obcaecati aliquid eaque libero similique hic?
          Dolore nam ducimus voluptates ea possimus sunt obcaecati non
          consequuntur eligendi nisi, delectus, doloribus quod distinctio
          libero, optio et tempora corrupti corporis repudiandae dolorum velit
          provident tempore. Labore id blanditiis magnam illo?
        </p>
        <div class="box2"></div>
        <p>
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Eveniet esse
          voluptates quibusdam qui unde. Totam nulla cupiditate expedita esse
          quam magni dolores, odit minima consequatur pariatur quidem culpa,
          necessitatibus saepe autem labore at ex sed. Aliquid odit expedita,
          dolorem neque rerum nihil a omnis cum praesentium quos impedit esse
          magnam, sequi earum laudantium repellat pariatur laboriosam hic dolore
          eos tempora quis eum! Obcaecati aliquid eaque libero similique hic?
          Dolore nam ducimus voluptates ea possimus sunt obcaecati non
          consequuntur eligendi nisi, delectus, doloribus quod distinctio
          libero, optio et tempora corrupti corporis repudiandae dolorum velit
          provident tempore. Labore id blanditiis magnam illo?
        </p>
        <p>
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Eveniet esse
          voluptates quibusdam qui unde. Totam nulla cupiditate expedita esse
          quam magni dolores, odit minima consequatur pariatur quidem culpa,
          necessitatibus saepe autem labore at ex sed. Aliquid odit expedita,
          dolorem neque rerum nihil a omnis cum praesentium quos impedit esse
          magnam, sequi earum laudantium repellat pariatur laboriosam hic dolore
          eos tempora quis eum! Obcaecati aliquid eaque libero similique hic?
          Dolore nam ducimus voluptates ea possimus sunt obcaecati non
          consequuntur eligendi nisi, delectus, doloribus quod distinctio
          libero, optio et tempora corrupti corporis repudiandae dolorum velit
          provident tempore. Labore id blanditiis magnam illo?
        </p>
        <p>
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Eveniet esse
          voluptates quibusdam qui unde. Totam nulla cupiditate expedita esse
          quam magni dolores, odit minima consequatur pariatur quidem culpa,
          necessitatibus saepe autem labore at ex sed. Aliquid odit expedita,
          dolorem neque rerum nihil a omnis cum praesentium quos impedit esse
          magnam, sequi earum laudantium repellat pariatur laboriosam hic dolore
          eos tempora quis eum! Obcaecati aliquid eaque libero similique hic?
          Dolore nam ducimus voluptates ea possimus sunt obcaecati non
          consequuntur eligendi nisi, delectus, doloribus quod distinctio
          libero, optio et tempora corrupti corporis repudiandae dolorum velit
          provident tempore. Labore id blanditiis magnam illo?
        </p>
      </article>
    </div>
              
            
!

CSS

              
                body {
      margin: 0;
      font-size: 35px;
    }

    .wrapper {
      max-width: 350px;
      margin: 0 auto;
    }

    .box1 {
      width: 320px;
      height: 200px;
      background-color: RGB(33, 128, 128);
    }

    .box2 {
      width: 350px;
      height: 200px;
      background-color: RGB(159, 176, 54);
    }

    p {
      font-size: 16px;
    }
              
            
!

JS

              
                const get = (cssSelector) => document.querySelector(cssSelector);

    const box1 = get(".box1");
    const box2 = get(".box2");

    function displayDistance() {
      console.log(window.scrollY);
      const box1_coordinate = box1.getBoundingClientRect();
      const box2_coordinate = box2.getBoundingClientRect();
      box1.innerHTML = `top距離: ${box1_coordinate.top}px
        bottom距離: ${box1_coordinate.bottom}px`;
      box2.innerHTML = `top距離: ${box2_coordinate.top}px
        bottom距離: ${box2_coordinate.bottom}px`;
    }

    window.addEventListener("scroll", displayDistance);
              
            
!
999px

Console