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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <p>
  Modified to:
</p>

<ol>
  <li>use <code>headers</code> attribute on spanning cell to associate it with a column header (which also needed an <code>id</code>);</li>
  <li>adjusted column headers to be distinct;</li>
  <li>fixed the buttons to act as disclosure widgets to convey their state (which meant each button and disclosed row also needed an <code>id</code> and each button got a simplified accName to not confict with its programmatic state);</li>
  <li>Remove numbers and the word 'column' from each cell to make the announcement easier to understand in screen readers;</li>
  <li>Refs:
    <ul>
      <li>Source pen: <a href="https://codepen.io/team/keyframers/pen/WNQQepr">codepen.io/team/keyframers/pen/WNQQepr</a></li>
      <li><a href="https://adrianroselli.com/2019/09/table-with-expando-rows.html">Table with Expando Rows</a></li>
    </ul>
  </li>
</ol>

<table>
  <thead>
    <tr class="summary">
      <th scope="col" id="Col1">Category</th>
      <th scope="col" id="Col2">Raw Data</th>
      <th scope="col" id="Col3">Something</th>
      <th scope="col" id="Col4">Action</th>
    </tr>
  </thead>
  <tbody data-flip-key="one" data-flip-no-scale>
    <tr>
      <th scope="row">Table row item</th>
      <td>Something</td>
      <td>Hammer sandwich</td>
      <td><a href="#">View a related item</a>
        <button class="show-details" aria-controls="RowX" aria-expanded="false" id="DetailsX" onclick="toggleDisclosure(this.id);">Details</button>
      </td>
    </tr>
    <tr class="details" id="RowX">
      <td colspan="4" headers="Col2">

        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent bibendum, lorem vel tincidunt imperdiet, nibh elit laoreet felis, a bibendum nisl tortor non orci. Donec pretium fermentum felis, quis aliquet est rutrum ut. Integer quis massa ut lacus viverra pharetra in eu lacus. Aliquam tempus odio adipiscing diam pellentesque rhoncus. Curabitur a bibendum est. Mauris vehicula cursus risus id luctus. Curabitur accumsan venenatis nibh, non egestas ipsum vulputate ac. Vivamus consectetur dolor sit amet enim aliquet eu scelerisque ipsum hendrerit. Donec lobortis suscipit vestibulum. Nullam luctus pellentesque risus in ullamcorper. Nam neque nunc, mattis vitae ornare ut, feugiat a erat. Ut tempus iaculis augue vel pellentesque.</p>

      </td>
    </tr>
  </tbody>

  <tbody data-flip-key="two" data-flip-no-scale>
    <tr class="summary">
      <th scope="row">Longer table row item</th>
      <td>A whole other thing</td>
      <td>Wrench taco</td>
      <td><a href="#">View a related item</a>
        <button class="show-details" aria-controls="RowY" aria-expanded="false" id="DetailsY" onclick="toggleDisclosure(this.id);">Details</button>
      </td>
    </tr>
    <tr class="details" id="RowY">
      <td colspan="4" headers="Col2">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent bibendum, lorem vel tincidunt imperdiet, nibh elit laoreet felis, a bibendum nisl tortor non orci. Donec pretium fermentum felis, quis aliquet est rutrum ut. Integer quis massa ut lacus viverra pharetra in eu lacus. Aliquam tempus odio adipiscing diam pellentesque rhoncus. Curabitur a bibendum est. Mauris vehicula cursus risus id luctus. Curabitur accumsan venenatis nibh, non egestas ipsum vulputate ac. Vivamus consectetur dolor sit amet enim aliquet eu scelerisque ipsum hendrerit. Donec lobortis suscipit vestibulum. Nullam luctus pellentesque risus in ullamcorper. Nam neque nunc, mattis vitae ornare ut, feugiat a erat. Ut tempus iaculis augue vel pellentesque.</p>
      </td>
    </tr>
  </tbody>

  <tbody data-flip-key="three" data-flip-no-scale>
    <tr class="summary">
      <th scope="row">Another table row item</th>
      <td>Another thing</td>
      <td>Pliers wrap</td>
      <td><a href="#">View a related item</a>
        <button class="show-details" aria-controls="RowZ" aria-expanded="false" id="DetailsZ" onclick="toggleDisclosure(this.id);">Details</button>
      </td>
    </tr>
    <tr class="details" id="RowZ">
      <td colspan="4" headers="Col2">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent bibendum, lorem vel tincidunt imperdiet, nibh elit laoreet felis, a bibendum nisl tortor non orci. Donec pretium fermentum felis, quis aliquet est rutrum ut. Integer quis massa ut lacus viverra pharetra in eu lacus. Aliquam tempus odio adipiscing diam pellentesque rhoncus. Curabitur a bibendum est. Mauris vehicula cursus risus id luctus. Curabitur accumsan venenatis nibh, non egestas ipsum vulputate ac. Vivamus consectetur dolor sit amet enim aliquet eu scelerisque ipsum hendrerit. Donec lobortis suscipit vestibulum. Nullam luctus pellentesque risus in ullamcorper. Nam neque nunc, mattis vitae ornare ut, feugiat a erat. Ut tempus iaculis augue vel pellentesque.</p>
      </td>
    </tr>
  </tbody>
</table>
<!--
<a href="https://youtu.be/SzTyZ-VUZuE" target="_blank" data-keyframers-credit style="color: #000" rel="noopener noreferrer"></a>
<script src="https://codepen.io/shshaw/pen/QmZYMG.js"></script>
-->
              
            
!

CSS

              
                * {
  box-sizing: border-box;
  position: relative;
}

p {
  margin: 0 0 1em;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  // background: white;
  // box-shadow: 0 .2em .75em rgba(0,0,0,.2);
}

thead {
  background: #ddd;
}

th {
  padding: 0.5rem 1rem;
}

tr {
  // border-bottom: 1px solid;
}

td,
th {
  padding: 0.25em 1em;
  text-align: left;
}

th:last-child,
td:last-child {
  text-align: right;
}

html {
  height: 100%;
  display: grid;
}
body {
  margin: 0 auto;
  padding: 2em;
  background: #9caac0;
}

.show-details {
  display: block;
  appearance: none;
  border: solid 2px #ccc;
  background: none;
  padding: 0.5em 1em;
  margin: 0.5em 0 0.5em auto;
}

.details {
  // background: #ccc;
  td {
    padding: 1em;
  }
}

/* ---------------------------------- */

tbody {
  transform-origin: top center;
  will-change: transform;
  background: #fff;
  > * {
    background: inherit;
  }
  z-index: 2;

  &::before {
    border-radius: 0.25em;
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    // margin: 0 -1em;
    background: #fff;
    z-index: -1;
    // opacity: 0;
    transform: scale(1);
    transition: box-shadow 0.4s linear, transform 0.3s ease-in-out;
  }
}

tbody:not([data-open]) {
  .details {
    display: none;
  }
}

tbody[data-open] {
  z-index: 4;

  &::before {
    box-shadow: 0 0em 0.5em rgba(#000, 0.3);
    transform: scale(1.025, 1);
  }

  .details {
    display: table-row;
    animation: details-reveal 0.3s ease-in-out both;
    @keyframes details-reveal {
      from {
        opacity: 0;
        transform: translateY(-1em);
        // clip-path: polygon(0 0, 100% 0, 100% 0%, 0% 0%);
      }
    }
  }
}

              
            
!

JS

              
                console.clear();

// FLIP
// F - First
// L - Last
// I - Invert
// P - Play

const flipping = new Flipping({
  easing: "cubic-bezier(.5, 0, .5, 1)"
});

let currentOpenEl;

Array.from(document.querySelectorAll(".show-details"), (button) => {
  let parent = button.closest("tbody");

  button.addEventListener(
    "click",
    flipping.wrap(() => {
      if (parent.dataset.open) {
        delete parent.dataset.open;
        currentOpenEl = null;
      } else {
        parent.dataset.open = true;

        if (currentOpenEl) {
          delete currentOpenEl.dataset.open;
        }

        currentOpenEl = parent;
      }
    })
  );
});

function toggleDisclosure(btnID) {
  // Get the button that triggered this
  var theButton = document.getElementById(btnID);
  // If the button is not expanded...
  if (theButton.getAttribute("aria-expanded") == "false") {
    // Now set the button to expanded
    theButton.setAttribute("aria-expanded", "true");
    // Otherwise button is not expanded...
  } else {
    // Now set the button to collapsed
    theButton.setAttribute("aria-expanded", "false");
  }
}

              
            
!
999px

Console