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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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 id="header">
  <h1>This is the Header</h1>
  <h2>We don't want to scroll up here after closing a modal.</h2>
  <h2>We'll also stop the page from scrolling when the modal is active.</h2>
  <h2>(Requires JavaScript)</h2>
  <h2 style="font-size: 50px;"><a href="#button-panel-anchor">&darr;</a></h2>
</header>

<section id="text-content-top">
  <p>Lorem ipsum dolor amet blog shabby chic cred hashtag ugh bushwick kinfolk meh irony retro shoreditch. Jianbing lyft ramps raclette shaman master cleanse thundercats austin. Tilde iPhone scenester organic, succulents meh asymmetrical palo santo man bun
    slow-carb wolf prism hot chicken. Distillery meditation PBR&B authentic farm-to-table pour-over selvage, succulents umami woke. Thundercats gastropub roof party butcher blue bottle etsy, man bun offal pour-over. Edison bulb forage gluten-free, tousled
    offal whatever drinking vinegar. Viral deep v coloring book before they sold out tacos.</p>

  <p>Paleo synth kickstarter wolf. YOLO meggings XOXO hoodie authentic street art craft beer fanny pack. Fashion axe chicharrones af iPhone. XOXO iceland brunch, wolf humblebrag kitsch marfa.</p>

  <p>Adaptogen schlitz try-hard lumbersexual before they sold out. Man bun flannel swag offal letterpress distillery celiac. Before they sold out gastropub portland, bushwick synth gochujang trust fund coloring book. Pop-up unicorn messenger bag, crucifix
    mlkshk shaman poutine artisan VHS franzen raw denim affogato bespoke bitters occupy. Normcore la croix shaman, poke raw denim marfa tousled godard williamsburg tacos jean shorts shoreditch chillwave vexillologist cred. Ramps irony glossier chia art
    party, ugh blog sartorial selfies mumblecore hot chicken. Thundercats deep v palo santo wolf drinking vinegar adaptogen pinterest godard distillery trust fund prism.</p>

  <p>Shaman dreamcatcher selfies scenester polaroid. Migas gentrify organic, drinking vinegar you probably haven't heard of them squid cold-pressed freegan trust fund marfa letterpress artisan af ethical. Distillery four loko tumeric, taiyaki beard 90's
    you probably haven't heard of them stumptown sartorial kogi VHS forage pop-up. Thundercats tacos edison bulb, pork belly mlkshk gastropub shaman vape. Sartorial chartreuse twee iceland edison bulb craft beer chicharrones flannel, lomo lumbersexual
    retro jianbing taiyaki.</p>

  <p>Four dollar toast live-edge cloud bread pickled banjo wayfarers YOLO +1 glossier ennui. Echo park shoreditch bushwick pork belly humblebrag 3 wolf moon authentic photo booth bitters literally selfies 90's leggings tofu PBR&B. Trust fund thundercats
    listicle, meh dreamcatcher selvage gentrify small batch paleo coloring book four loko tousled taiyaki freegan leggings. Cray affogato knausgaard meditation health goth irony flexitarian pop-up flannel plaid tbh. Retro echo park single-origin coffee
    prism coloring book paleo four dollar toast YOLO next level 3 wolf moon knausgaard hot chicken man braid banh mi.</p>

  <p>Oh. You need a little dummy text for your mockup? How quaint.</p>

  <p>I bet you’re still using Bootstrap too…</p>
</section>

<div id="button-panel-anchor" style="margin-bottom: 8%;">&nbsp;</div>

<section id="button-panel">
  <div class="modal-overlay closed" id="modal-overlay"></div>

  <div class="modal closed" id="modal">
    <button class="close-button" id="close-button">Close</button>
    <div class="modal-guts">
      <h1>I Play Nice</h1>
      <p><strong>You can't <em>scroll</em> the page when I'm open. And, when you close me, I won't <em>punt</em> you to the top of the page.</strong></p>
      <p>Tumblr anim hashtag qui tumeric. Mlkshk polaroid dolore reprehenderit forage tumblr put a bird on it intelligentsia aesthetic williamsburg slow-carb mixtape microdosing. Jean shorts celiac ugh, tempor sartorial tbh readymade. Labore in lumbersexual hexagon tbh migas yuccie williamsburg lomo qui bushwick vegan. Organic hella vaporware, ea humblebrag banjo PBR&B helvetica pour-over commodo celiac shoreditch. Godard trust fund taiyaki, unicorn cliche eiusmod mixtape dolore quis. Gochujang venmo la croix, ramps skateboard live-edge humblebrag gluten-free irure heirloom.</p>
      <p>Words courtesy of <a href="https://hipsum.co/">Hipster Ipsum</a>.</p>

    </div>
  </div>

  <button id="open-button" class="open-button">Open Modal</button>

</section>

<section id="text-content-bottom">
  <p>Lorem ipsum dolor amet blog shabby chic cred hashtag ugh bushwick kinfolk meh irony retro shoreditch. Jianbing lyft ramps raclette shaman master cleanse thundercats austin. Tilde iPhone scenester organic, succulents meh asymmetrical palo santo man bun
    slow-carb wolf prism hot chicken. Distillery meditation PBR&B authentic farm-to-table pour-over selvage, succulents umami woke. Thundercats gastropub roof party butcher blue bottle etsy, man bun offal pour-over. Edison bulb forage gluten-free, tousled
    offal whatever drinking vinegar. Viral deep v coloring book before they sold out tacos.</p>

  <p>Paleo synth kickstarter wolf. YOLO meggings XOXO hoodie authentic street art craft beer fanny pack. Fashion axe chicharrones af iPhone. XOXO iceland brunch, wolf humblebrag kitsch marfa.</p>

  <p>Adaptogen schlitz try-hard lumbersexual before they sold out. Man bun flannel swag offal letterpress distillery celiac. Before they sold out gastropub portland, bushwick synth gochujang trust fund coloring book. Pop-up unicorn messenger bag, crucifix
    mlkshk shaman poutine artisan VHS franzen raw denim affogato bespoke bitters occupy. Normcore la croix shaman, poke raw denim marfa tousled godard williamsburg tacos jean shorts shoreditch chillwave vexillologist cred. Ramps irony glossier chia art
    party, ugh blog sartorial selfies mumblecore hot chicken. Thundercats deep v palo santo wolf drinking vinegar adaptogen pinterest godard distillery trust fund prism.</p>

  <p>Shaman dreamcatcher selfies scenester polaroid. Migas gentrify organic, drinking vinegar you probably haven't heard of them squid cold-pressed freegan trust fund marfa letterpress artisan af ethical. Distillery four loko tumeric, taiyaki beard 90's
    you probably haven't heard of them stumptown sartorial kogi VHS forage pop-up. Thundercats tacos edison bulb, pork belly mlkshk gastropub shaman vape. Sartorial chartreuse twee iceland edison bulb craft beer chicharrones flannel, lomo lumbersexual
    retro jianbing taiyaki.</p>

  <p>Four dollar toast live-edge cloud bread pickled banjo wayfarers YOLO +1 glossier ennui. Echo park shoreditch bushwick pork belly humblebrag 3 wolf moon authentic photo booth bitters literally selfies 90's leggings tofu PBR&B. Trust fund thundercats
    listicle, meh dreamcatcher selvage gentrify small batch paleo coloring book four loko tousled taiyaki freegan leggings. Cray affogato knausgaard meditation health goth irony flexitarian pop-up flannel plaid tbh. Retro echo park single-origin coffee
    prism coloring book paleo four dollar toast YOLO next level 3 wolf moon knausgaard hot chicken man braid banh mi.</p>

  <p>Oh. You need a little dummy text for your mockup? How quaint.</p>

  <p>I bet you’re still using Bootstrap too…</p>
</section>
              
            
!

CSS

              
                header {
  min-height: 200px;
  border: 2px solid white;
  background: black;
}

a {
  text-decoration: none;
  color: #F05E35;
}

section {
  margin: 15% 5%;
}

@import 'https://fonts.googleapis.com/css?family=Prompt:400,700';

.modal {
  /* This way it could be display flex or grid or whatever also. */
  display: block;
  
  /* Probably need media queries here */
  width: 600px;
  max-width: 100%;
  
  height: 450px;
  max-height: 100%;
  
  position: fixed;
  
  z-index: 100;
  
  left: 50%;
  top: 50%;
  
  /* Use this for centering if unknown width/height */
  transform: translate(-50%, -50%);
  
  /* If known, negative margins are probably better (less chance of blurry text). */
  /* margin: -200px 0 0 -200px; */
  
  background: white;
  box-shadow: 0 0 60px 10px rgba(0, 0, 0, 0.9);
}
.closed {
  display: none;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 50;
  
  background: rgba(0, 0, 0, 0.6);
}
.modal-guts {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: 20px 50px 20px 20px;
}



* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  background-color:#777;
  /*
  background-image: linear-gradient(30deg, #445 12%, transparent 12.5%, transparent 87%, #445 87.5%, #445),
  linear-gradient(150deg, #445 12%, transparent 12.5%, transparent 87%, #445 87.5%, #445),
  linear-gradient(30deg, #445 12%, transparent 12.5%, transparent 87%, #445 87.5%, #445),
  linear-gradient(150deg, #445 12%, transparent 12.5%, transparent 87%, #445 87.5%, #445),
  linear-gradient(60deg, #99a 25%, transparent 25.5%, transparent 75%, #99a 75%, #99a), 
  linear-gradient(60deg, #99a 25%, transparent 25.5%, transparent 75%, #99a 75%, #99a);
  background-size:80px 140px;
  background-position: 0 0, 0 0, 40px 70px, 40px 70px, 0 0, 40px 70px; */
  
  font-family: 'Prompt', sans-serif;
}
ul {
  margin: 10px 0 10px 30px;
}
li, p {
  margin: 0 0 10px 0;
}
h1, h2 {
  margin: 1em 0 1em 0;
  color: white;
  text-align: center;
  font-weight: normal;
}

h1 {
  font-size: 2.5rem;
}

h2 {
  font-size: 1.5rem;
}

.modal-guts h1 {
  color: black;
}

.modal .close-button {
  position: absolute;
  
  /* don't need to go crazy with z-index here, just sits over .modal-guts */
  z-index: 1;
  
  top: 10px;
  
  /* needs to look OK with or without scrollbar */
  right: 20px;
  
  border: 0;
  background: black;
  color: white;
  padding: 5px 10px;
  font-size: 1.3rem;
  border-radius: 10px;
}

.open-button {
  border: 0;
  position: relative;
  top: 80%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: black;
  color: white;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 21px;
}

.open-button:hover, 
.modal .close-button:hover {
  cursor: pointer;
}
              
            
!

JS

              
                /**
 * Revision History
 * 
 * 1 Mar 2022 - Replaced var with const.
 * 12 Jan 2020 - Added code to stop page scrolling when modal
 *               is active.
 */
const modal = document.querySelector("#modal"),
  modalOverlay = document.querySelector("#modal-overlay"),
  closeButton = document.querySelector("#close-button"),
  openButton = document.querySelector("#open-button"),
  body = document.body;

closeButton.addEventListener("click", function() {
  modal.classList.toggle("closed");
  modalOverlay.classList.toggle("closed");
  /* The scroll position when modal is opened
     is lost when body is fixed. So, retrieve
     the original position when modal is closed. */
  const scrollY = body.style.top;
  body.style.position = '';
  body.style.top = '';
  window.scrollTo(0, parseInt(scrollY || '0') * -1);
});

openButton.addEventListener("click", function() {
  modal.classList.toggle("closed");
  modalOverlay.classList.toggle("closed");
  /* Special code for remembering scroll position then 
     disabling scroll when modal is open. */
  const scrollY = 
        document.documentElement.style.getPropertyValue('--scroll-y');
  body.style.position = 'fixed';
  body.style.top = `-${scrollY}`;
});

window.addEventListener('scroll', () => {
  document.documentElement.style.setProperty('--scroll-y', `${window.scrollY}px`);
});

              
            
!
999px

Console