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

              
                <h1>What is this?</h1>
<p>Just me trying to recreate TelescopicText for <a href="https://0xff.nu">my website</a> without relying on JavaScript.</p>
<p>Made on the 24th of November, 2024 by <a href="https://bsky.app/profile/0xff.nu ">Paul</a>.</p>

<h2>The <code>radio</code> way</h2>
<blockquote>
  The usual <code>checked</code> wizardry, except with a <code>radio</code> element instead of <code>checkbox</code> to prevent closing.
</blockquote>
<p>
  My name is <input type="radio" id="hxii"><label for="hxii" more=", and I live on planet earth">hxii</label>.
</p>

<h2>The <code>details</code> way</h2>

<blockquote>
  This requires a <code>div</code> elements instead of <code>p</code> as paragraph gets closed thus making <code>details</code> take its own line.
</blockquote>

<div>
  <span>I own </span>
  <details>
    <summary>two cats</summary>a cat named Yoda, and a cat named Pie.
    <details>
      <summary>They are very cute.</summary>I like them very much and they bring me comfort.
    </details>
  </details>

</div>

<h2>Minimal JS Way</h2>
<blockquote>While the <code>&lt;details&gt;</code> is working when written manually, I found it so far impossible to get working with Python-Markdown, thus let's try a JS-minimal way.</blockquote>

<div class="expando">
  <p>
  <ul>
<li>My name</li>
<li>is hxii<ul>
<li>is hxii (or Paul Glushak)</li>
</ul>
</li>
<li>and I like to code<ul>
<li>and I like to write code, but</li>
<li>that's not my primary title<ul>
<li>I work as a team lead primarily and developer secondarily.</li>
</ul>
</li>
</ul>
</li>
<li>and make</li>
<li>cool things<ul>
<li>cool things that </li>
<li>help others<ul>
<li>help others make cool things</li>
</ul>
</li>
</ul>
</li>
<li>.</li>
</ul>
  </p>
</div>
              
            
!

CSS

              
                /* Make codepen more pleasant, exclude this later */

body {
  font: 16px/1.6 -system-ui, sans-serif;
  padding: 5rem;
  background: #eee;
}

code {
  background: #00000011;
  padding: 0.1rem 0.25rem;
  border: 1px solid #00000022;
}

blockquote {
  margin: 1rem 0;
  padding: 1rem;
  border: 2px solid #00000022;
  border-radius: 4px;
  max-width: fit-content;
}

/* END PLESANTRIES -------------- */

/* RADIO WAY */

input[type="radio"] {
  display: none;
}

input[type="radio"] + label {
  background: #ddd;
}

input[type="radio"] + label:hover {
  background: #ccc;
}

input[type="radio"]:checked + label {
  background: initial;
  padding: 0;
}

input[type="radio"]:checked + label::after {
  content: attr(more);
  display: inline;
}

/* END RADIO ---------- */
/* DETAILS WAY */

details {
  display: inline-block;
  width: auto;
  max-width: fit-content;
}

details > summary {
  background: #ddd;
  display: inline;
}

details[open] > summary {
  display: none;
}

details summary > * {
  display: inline;
}

/* END DETAILS */

/* LIST WAY + JS */

div.expando ul {
  display: block;
  margin: 0;
  padding: 0;
}

div.expando ul li {
  display: inline;
}

div.expando li > ul {
  display: none;
}

div.expando li > ul.expanded {
  display: inline;
}

/* ul.expanded ul.expanded {
  display: inline;
} */

/* END LIST WAY */
              
            
!

JS

              
                document.addEventListener('DOMContentLoaded', () => {
  document.querySelectorAll('div.expando ul > li').forEach((li) => {
    const nestedUl = li.querySelector(':scope > ul'); // Select direct child <ul>

    if (nestedUl) {
      // Style only <li> elements with nested lists
      li.style.cursor = 'pointer';
      li.style.color = 'blue';
      li.style.textDecoration = 'underline';

      li.addEventListener('click', () => {
        // Remove the text content of the clicked <li>, keep the nested list
        li.firstChild.textContent = ''; // Remove the initial text
        nestedUl.classList.add('expanded'); // Reveal the nested list
        li.style.cursor = 'default'; // Disable pointer styling after click
        li.style.color = ''; // Reset color styling after expansion
        li.style.textDecoration = ''; // Reset underline after expansion
      });
    }
  });
});

              
            
!
999px

Console