Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <script type="module" src="https://spicy-sections.glitch.me/SpicySections.js"></script>

<h1>
  Showing off Spicy Sections
</h1>
<p>
  This demo shows different designed affordances at different screen sizes (resize your viewport and view the source too)…
</p>
<ul>
  <li><code>0-30em</code>: collapsable sections</li>
  <li><code>30-60em</code>: structured content</li>
  <li><code>60em+</code>: tab-bar</li>
</ul>

<spicy-sections id="demos">
  <h2>Tabs</h2>
  <div>
    <p>
      The <code>tab-bar</code> affordance
      can use shadow-dom to establish
      a styleable tab-bar and panels.
      The required parts can be exposed for styling
      with consistent pseudo-elements.
    </p>
    <p>
      In a tab state, we likely want to style:
    </p>
    <ul>
      <li>The outer box</li>
      <li>The tab bar</li>
      <li>The tabs themselves</li>
      <li>The selected tab</li>
      <li>The tab panel area</li>
    </ul>
  </div>
  <h2>Collapse</h2>
  <div>
    <p>
      The accordion-like <code>collapse</code> affordance
      also uses shadow-dom to establish
      summary-details like behavior for each section,
      with an option to make the toggle-states
      <code>exclusive-collapse</code>.
    </p>
    <p>
      In an accordion state, we likely want to style:
    </p>
    <ul>
      <li>The outer box</li>
      <li>The section headings/buttons</li>
      <li>The open/closed marker</li>
      <li>Open and closed heading styles</li>
      <li>Open and closed content styles</li>
    </ul>
  </div>
  <h2>Structured Content</h2>
  <div>
    <p>
      The fallback state is simply structured HTML,
      without any show/hide affordances.
      This does not require any special styling.
    </p>
  </div>
</spicy-sections>
              
            
!

CSS

              
                spicy-sections {
  /* Big hand-wave over how we'd ultimately express this, but for this custom element, this is how you inform when you'd like to emply which affodances 'collapse', 'tab-bar' and 'exclusive-collapse' are the available affordances.  Anything else is, effectively "plain" or "none". It is only read once.
  */
  --const-mq-affordances: [screen and (max-width: 40em) ] collapse | [screen and
    (min-width: 60em) ] tab-bar;
  display: block;
  border: thick var(--demo-border, solid black);
  border-width: thick 0;
  padding: 1em;
}

/* just normal css/dom any heading works */
h2 {
  font-size: var(--heading-size, 1.2em);
  margin: 0;
}

/* you can tell there are none employed */
h2:not([affordance] *) {
  margin-bottom: 0.5em;
}

/* content panels when plain */
h2:not([affordance] *):not(:first-child) {
  margin-top: 1.5em;
}

/* content panels, always */
spicy-sections h2 + * {
  margin-top: 0;
}

/* accordion buttons */
[affordance="collapse"] {
  --heading-size: 1em;
  --demo-border: dotted tomato;
}

/* structured content */
spicy-sections:not([affordance]) {
  --demo-border: dashed teal;
}

/* tabs */
[affordance="tab-bar"] {
  --demo-border: solid mediumvioletred;
}

/* the pseudo element created around the tabs, when it exists */
::part(tab-list) {
  display: flex;
}

/* only when they're tabs */
[affordance="tab-bar"] h2 {
  padding: 0.125em 0.5em;
  cursor: pointer;
}

/* Only when they're tabs and selected */
[affordance="tab-bar"] h2[tabindex="0"] {
  background: papayawhip;
  border: 0;
}

/* Tabs that aren't selected */
[affordance="tab-bar"] h2:not([tabindex="0"]) {
  color: gray;
}

/* content, when it's tabs */
[affordance="tab-bar"] [role="tabpanel"] {
  background: papayawhip;
  padding: 1em;
}

              
            
!

JS

              
                
              
            
!
999px

Console