123

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <main class="[ container ] [ flow ]">
  <h1>Buy this thing!</h1>
  <p>It is very good and there's absolutely no hidden exceptions!</p>
  <a href="//example.com" class="button">Buy it now!!</a>
  <div class="terms">
    <button class="[ link-button ] [ js-trigger ]" type="button" hidden>
      See the terms & conditions
      <svg viewBox="0 0 512 512" aria-hidden="true" fill="currentColor" width="1em" height="1em">
        <path d="M60 99.333l196 196 196-196 60 60-256 256-256-256z"></path>
      </svg>
    </button>
    <div class="[ panel ] [ js-panel ]">
      <article class="[ panel__inner ] [ js-panel__inner ]">
        <p>Here's some secret terms and conditions that we didn't want you to see because they explain how the product isn't actually very good. </p>

        <p>
          Lorem ipsum dolor sit amet, appareat pertinax et ius, ne pro nibh consulatu consetetur, nulla virtute definitiones nec in. Ad consul feugait eligendi mea, mutat tamquam ei mei. No hinc graecis phaedrum pro, cu erat ipsum sed, ut novum dissentiunt
          ullamcorper pro. <a href="#">Dicat aliquid dissentias</a> in per, meis alterum quaestio mei eu, vero praesent ex eam. Ei nam homero noluisse dissentiunt, ut vim quot putent. Vis elitr accusam accommodare id, cu usu quaestio conceptam, habeo tibique placerat eos
          cu. An nullam corpora consulatu qui, graeci euripidis est et.
        </p>
        <p>
          In tantas scripta nominati quo, ne essent maluisset voluptaria nam. Dicat putent feugiat ei sed, te vis delicata gubergren honestatis, ius liber blandit delicata ut. Vix et dictas detracto voluptua, vis an inani dicunt. Qui inciderint intellegebat ea,
          cetero verear cu duo.
        </p>
        <p>
          Vix id etiam sapientem. Vix case velit feugait eu. Id diceret delenit perpetua vis, has sale utamur aeterno te. Cum et consetetur mediocritatem.
        </p>
      </article>
    </div>
  </div>
</main>
            
          
!
            
              /* General presentation styles */

html {
  background: #212d40;
}

body,
.button,
.link-button {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

body {
  padding: 1.5rem;
  line-height: 1.4;
  color: #f3f3f3;
}

p {
  margin: 0;
}

article > * + * {
  margin-top: 1.5em;
}

hr {
  border: none;
  border-top: 1px dashed #ccc;
  margin: 1.5rem 0;
}

a:not([class]) {
  color: currentcolor;
}

a:not([class]):hover,
a:not([class]):focus {
  text-decoration: none;
}

.container {
  max-width: 30rem;
  margin: 0 auto;
}

.terms {
  --flow-space: 2rem;
}

/* Flow utility, which I write about here: https://24ways.org/2018/managing-flow-and-rhythm-with-css-custom-properties/ */
.flow {
  --flow-space: 1em;
}

.flow > * + * {
  margin-top: var(--flow-space);
}

/* Button component */
.button {
  display: inline-block;
  border: none;
  padding: 0.6rem 1.2rem 0.8rem 1.2rem;
  text-decoration: none;
  background: #98b06f;
  color: #212d40;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: background 250ms ease-in-out, transform 150ms ease;
  -webkit-appearance: none;
  -moz-appearance: none;
}

.button:hover,
.button:focus {
  background: #ffffff;
}

.button:focus {
  outline: 1px solid #212d40;
  outline-offset: -4px;
}

.button:active {
  transform: scale(0.99);
}

/* Link button component */


.link-button {
  display: none; /* We hide this button by default / if there's no JS available */
  text-decoration: underline;
  text-decoration-skip-ink: auto;
  background: transparent;
  padding: 0;
  margin: 0;
  border: 0;
  color: #98b06f;
  font-size: 1rem;
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
}

/* When the link-button has a correct aria attribute, we can show it */
.link-button[aria-expanded] {
  display: inline-flex;
  align-items: center;
}

.link-button svg {
  opacity: 0.8;
  margin-left: 0.5rem;
  transition: all 250ms ease-in-out;
  font-size: 0.8rem;
}

.link-button[aria-expanded="true"] svg {
  transform: rotate(-180deg);
}

.link-button:hover,
.link-button:focus {
  text-decoration: none;
}

.link-button:focus {
  text-decoration: none;
  outline: 1px solid rgba(255, 255, 255, 0.4);
  outline-offset: 0.6rem;
}

.link-button:active {
  transform: scale(0.99);
}

/* Panel component which is completely controlled by a valid sibling 
   button element, such as the link button. We only conceal the content 
   if its sibling button has the correct aria attribute, so we can enforce
   accessibility and progressively enhance the UI */
[aria-expanded] + .panel {
  --panel-max-height: 500px;

  transition: all 200ms ease;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 0;
  visibility: hidden;
  -webkit-overflow-scrolling: touch;
}

[aria-expanded] + .panel .panel__inner {
  transition: all 500ms ease;
  transition-delay: 50ms;
  opacity: 0;
  transform: translateY(1rem);
  padding-top: 1.5rem;
}

[aria-expanded="true"] + .panel {
  max-height: var(--panel-max-height);
  visibility: visible;
}

[aria-expanded="true"] + .panel .panel__inner {
  opacity: 1;
  transform: translateY(0);
}

            
          
!
            
              console.clear();


const trigger = document.querySelector('.js-trigger');
const panel = document.querySelector('.js-panel');
const panelInner = document.querySelector('.js-panel__inner');

// This is the CSS Custom Property that is updated with the panel's content's height
const maxHeightKey = '--panel-max-height';

let state = {
  triggerExpanded: 'collapsed'
}


// Sets the relevant aria role based on its current value. Sets it to false by default
// if no value is set
const setTriggerState = () => {
  let currentExpandedState = trigger.getAttribute('aria-expanded');
    
  // If it's not set yet, set it to true so it is reversed below
  if(currentExpandedState === null) {
    currentExpandedState = 'true';
  }
  
  // Update our global state so other functions know what's up
  state.triggerExpanded = currentExpandedState === 'true' ? 'false' : 'true'
  
  trigger.setAttribute('aria-expanded', state.triggerExpanded);
  trigger.removeAttribute('hidden');
};

// Looks for content within the panel and calculates its height. This makes the transition smoother.
// Returns a promise so it can do its job before the toggle starts
const setMaxHeight = () => {
  
  return new Promise((resolve, reject) => {
    if(!panel || !panelInner) {
      reject();
    }  

    panel.style.setProperty(maxHeightKey, `${panelInner.getBoundingClientRect().height}px`);
    resolve();
  });
};

const run = () => {
  setMaxHeight()
  .then(() => setTriggerState());
};

trigger.addEventListener('click', run);

run();
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console