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

              
                <main>
  <h1>Responsive, Accessible Table Experiments</h1>
  <p>
    For the love of <code>$deity</code>, do not do not copy this.
  </p>
  <p>
    Using a pile of ARIA roles, I am converting this list to a table for assistive technology. The styles will allow the table to rotate to fit smaller viewports. Obviously this use is very niche.
  </p>
  <div role="grid" aria-readonly="true" aria-labelledby="cc" class="t1">
    <p id="cc">
      Table made of unordered list using CSS flex.
    </p>
    <ul role="row">
      <li role="columnheader" id="c1">Red</li>
      <li role="columnheader" id="c2">Blue</li>
      <li role="columnheader" id="c3">Green</li>
      <li role="columnheader" id="c4">Cyan</li>
      <li role="columnheader" id="c5">Magenta</li>
      <li role="columnheader" id="c6">Yellow</li>
      <li role="columnheader" id="c7">Black</li>
    </ul>
    <ul role="row">
      <li role="gridcell" aria-describedby="c1">R </li>
      <li role="gridcell" aria-describedby="c2">G</li>
      <li role="gridcell" aria-describedby="c3">B</li>
      <li role="gridcell" aria-describedby="c4">C</li>
      <li role="gridcell" aria-describedby="c5">M</li>
      <li role="gridcell" aria-describedby="c6">Y</li>
      <li role="gridcell" aria-describedby="c7">K</li>
    </ul>
    <ul role="row">
      <li role="gridcell" aria-describedby="c1">1</li>
      <li role="gridcell" aria-describedby="c2">2</li>
      <li role="gridcell" aria-describedby="c3">3</li>
      <li role="gridcell" aria-describedby="c4">4</li>
      <li role="gridcell" aria-describedby="c5">5</li>
      <li role="gridcell" aria-describedby="c6">6</li>
      <li role="gridcell" aria-describedby="c7">7</li>
    </ul>
  </div>
  <p>
    Insert the same HTML but which uses CSS display table properties.
  </p>
    <div role="grid" aria-readonly="true" aria-labelledby="cc2" class="t2">
    <p id="cc2">
      Table made of unordered list using CSS table layout.
    </p>
    <ul role="row">
      <li role="columnheader" id="c1-2">Red</li>
      <li role="columnheader" id="c2-2">Blue</li>
      <li role="columnheader" id="c3-2">Green</li>
      <li role="columnheader" id="c4-2">Cyan</li>
      <li role="columnheader" id="c5-2">Magenta</li>
      <li role="columnheader" id="c6-2">Yellow</li>
      <li role="columnheader" id="c7-2">Black</li>
    </ul>
    <ul role="row">
      <li role="gridcell" aria-describedby="c1-2">R</li>
      <li role="gridcell" aria-describedby="c2-2">G</li>
      <li role="gridcell" aria-describedby="c3-2">B</li>
      <li role="gridcell" aria-describedby="c4-2">C</li>
      <li role="gridcell" aria-describedby="c5-2">M</li>
      <li role="gridcell" aria-describedby="c6-2">Y</li>
      <li role="gridcell" aria-describedby="c7-2">K</li>
    </ul>
    <ul role="row">
      <li role="gridcell" aria-describedby="c1-2">1</li>
      <li role="gridcell" aria-describedby="c2-2">2</li>
      <li role="gridcell" aria-describedby="c3-2">3</li>
      <li role="gridcell" aria-describedby="c4-2">4</li>
      <li role="gridcell" aria-describedby="c5-2">5</li>
      <li role="gridcell" aria-describedby="c6-2">6</li>
      <li role="gridcell" aria-describedby="c7-2">7</li>
    </ul>
  </div>
  <p>
    Now in a definition list.
  </p>
      <div role="grid" aria-readonly="true" aria-labelledby="cc3" class="t3">
    <p id="cc3">
      Table made of definition list using CSS floats (larger screen size) and flex (smaller).
    </p>
    <dl role="row">
      <dt role="columnheader" id="c1-3">Red</dt>
      <dd role="gridcell" aria-describedby="c1-3">R</dd>
      <dd role="gridcell" aria-describedby="c1-3">1</dd>
    </dl>
    <dl role="row">
      <dt role="columnheader" id="c2-3">Blue</dt>
      <dd role="gridcell" aria-describedby="c2-3">G</dd>
      <dd role="gridcell" aria-describedby="c2-3">2</dd>
    </dl>
    <dl role="row">
      <dt role="columnheader" id="c3-3">Green</dt>
      <dd role="gridcell" aria-describedby="c3-3">B</dd>
      <dd role="gridcell" aria-describedby="c3-3">3</dd>
    </dl>
    <dl role="row">
      <dt role="columnheader" id="c4-3">Cyan</dt>
      <dd role="gridcell" aria-describedby="c4-3">C</dd>
      <dd role="gridcell" aria-describedby="c4-3">4</dd>
    </dl>
    <dl role="row">
      <dt role="columnheader" id="c5-3">Magenta</dt>
      <dd role="gridcell" aria-describedby="c5-3">M</dd>
      <dd role="gridcell" aria-describedby="c5-3">5</dd>
    </dl>
    <dl role="row">
      <dt role="columnheader" id="c6-3">Yellow</dt>
      <dd role="gridcell" aria-describedby="c6-3">Y</dd>
      <dd role="gridcell" aria-describedby="c6-3">6</dd>
    </dl>
    <dl role="row">
      <dt role="columnheader" id="c7-3">Black</dt>
      <dd role="gridcell" aria-describedby="c7-3">K</dd>
      <dd role="gridcell" aria-describedby="c7-3">7</dd>
    </dl>
  </div>
  <p>
    Now in a definition list, again
  </p>
      <div role="grid" aria-readonly="true" aria-labelledby="cc4" class="t4">
    <p id="cc4">
      Table made of definition list using CSS floats (larger screen size) and flex (smaller). There is no column role in ARIA, so this is dead in the water.
    </p>
    <dl role="row"><!-- crap, there is no column role -->
      <dt role="columnheader" id="c1-4">Red</dt>
      <dd role="gridcell" aria-describedby="c1-4">R</dd>
      <dd role="gridcell" aria-describedby="c1-4">1</dd>
    </dl>
    <dl role="row">
      <dt role="columnheader" id="c2-4">Blue</dt>
      <dd role="gridcell" aria-describedby="c2-4">R</dd>
      <dd role="gridcell" aria-describedby="c2-4">2</dd>
    </dl>
    <dl role="row">
      <dt role="columnheader" id="c3-4">Green</dt>
      <dd role="gridcell" aria-describedby="c3-4">B</dd>
      <dd role="gridcell" aria-describedby="c3-4">3</dd>
    </dl>
    <dl role="row">
      <dt role="columnheader" id="c4-4">Cyan</dt>
      <dd role="gridcell" aria-describedby="c4-4">C</dd>
      <dd role="gridcell" aria-describedby="c4-4">4</dd>
    </dl>
    <dl role="row">
      <dt role="columnheader" id="c5-4">Magenta</dt>
      <dd role="gridcell" aria-describedby="c5-4">M</dd>
      <dd role="gridcell" aria-describedby="c5-4">5</dd>
    </dl>
    <dl role="row">
      <dt role="columnheader" id="c6-4">Yellow</dt>
      <dd role="gridcell" aria-describedby="c6-4">Y</dd>
      <dd role="gridcell" aria-describedby="c6-4">6</dd>
    </dl>
    <dl role="row">
      <dt role="columnheader" id="c7-4">Black</dt>
      <dd role="gridcell" aria-describedby="c7-4">K</dd>
      <dd role="gridcell" aria-describedby="c7-4">7</dd>
    </dl>
  </div>
  
  <p>
    The same data as above, except this is a regular HTML table. It should be announced the same as the prior table. No ARIA role re-mapping here as none is needed.
  </p>
  <table>
    <caption>The caption for the real table.</caption>
    <tr>
      <th>Red</th>
      <th>Blue</th>
      <th>Green</th>
      <th>Cyan</th>
      <th>Magenta</th>
      <th>Yellow</th>
      <th>Black</th>
    </tr>
    <tr>
      <td>R</td>
      <td>G</td>
      <td>B</td>
      <td>C</td>
      <td>M</td>
      <td>Y</td>
      <td>K</td>
    </tr>
    <tr>
      <td>1</td>
      <td>2</td>
      <td>3</td>
      <td>4</td>
      <td>5</td>
      <td>6</td>
      <td>7</td>
    </tr>
  </table>
</main>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Lato:400,700);
body {
  background-color: #6D695C;
  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAACVBMVEUAAAAAAAAAAACDY+nAAAAAA3RSTlMmDQBzGIDBAAAAG0lEQVR42uXIIQEAAADCMHj/0NdkQMws0HEeAqvwAUGJthrXAAAAAElFTkSuQmCC);
  font-size: 100%;
  color: #333;
  font-family: Lato, Arial, sans-serif;
  padding: 0;
  margin: 0;
}

main {
  display: block;
  box-sizing: border-box;
  width: 90%;
  margin: 1em auto;
  padding: 1em 2em;
  color: #000;
  background-color: rgba(204, 204, 204, .7);
  border: .07em solid rgba(0, 0, 0, .5);
  border-radius: .5em;
}


/* Base styles for the fake tables */

  [role=grid], table {
    border-collapse: collapse;
    box-sizing: border-box;
    padding: 0;
    transition: all .2s;
    /*border: 1px dotted #f00;*/
  }
  [role=grid] > p {
    text-align: center;
    margin: .5em;
  }
  [role=grid] > * {
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    list-style-type: none;
    transition: all .2s;
  }
  [role=grid] > * > *, td, th {
    box-sizing: border-box;
    padding: .25em .5em;
    margin: 0;
    list-style-type: none;
    border: 1px solid #000;
    transition: all 0.5s ease-out;
  }
  [role=columnheader], th {
    background-color: #666;
    color: #fff;
    font-weight: bold;
    border-color: #000;
  }





@media all and (min-width: 35em) {
  /* Use the min width from below plus container spacing */
  
  /* For the list converted to flex */
  .t1[role=grid] {
    min-width: 10em; /* Choose a value based on the content */
    max-width: 34em;
  }
  .t1[role=grid] > * {
    display: flex;
    flex-wrap: nowrap;
  }
  .t1[role=grid] > * > * {
    flex: 1 0 2.75em;
  }
  [role=grid] > ul:not(:last-child) > * {
    border-bottom: none;
  }
  [role=grid] > ul > *:not(:last-child) {
    border-right: none;
  }
  
  /* For the list converted to table  */
  .t2[role=grid] > p {
    display: table-caption;
  }
  .t2[role=grid] {
    display: table;
  }
    .t2[role=grid] > * {
    display: table-row;
  }
    .t2[role=grid] > * > * {
    display: table-cell;
  }
  .t2[role=grid] > *:not(:last-child) > * {
    border-bottom: none;
  }
  .t2[role=grid] > * > *:not(:last-child) {
    border-right: none;
  }
  .t2 [role=columnheader] {
    vertical-align: bottom;
  }
  
  
  
  /* For the definition list converted to table  */
  .t3[role=grid]::after {
    content: "";
    margin: 0;
    padding: 0;
    display: block;
    clear: both;
  }
  .t3[role=grid] > dl {
    float: left;
  }
  .t3[role=grid] > dl:not(:last-child) > * {
    border-right: none;
  }
  .t3[role=grid] > dl > *:not(:last-child) {
    border-bottom: none;
  }
  
  /* For the definition list converted to table  */
  .t4[role=grid] > p {
    display: table-caption;
  }
  .t4[role=grid] {
    display: table;
  }
    .t4[role=grid] > * {
    display: table-row;
  }
    .t4[role=grid] > * > * {
    display: table-cell;
  }
  .t4[role=grid] > dl:not(:last-child) > * {
    border-bottom: none;
  }
  .t4[role=grid] > dl > *:not(:last-child) {
    border-right: none;
  }
  
  /* For the definition list converted to table  */
  .t4[role=grid] > p {
    display: table-caption;
  }
  .t4[role=grid] {
    display: table;
  }
    .t4[role=grid] > * {
    /*display: table-column;*/
  }
    .t4[role=grid] > * > * {
    display: table-cell;
  }
}

@media all and (max-width: 34.99em) {
  
  /* For the two bullet lists */
  [role=grid]::after {
    content: "";
    margin: 0;
    padding: 0;
    display: block;
    clear: both;
  }
  [role=grid] > ul {
    float: left;
  }
  [role=grid] > ul:not(:last-child) > * {
    border-right: none;
  }
  [role=grid] > ul > *:not(:last-child) {
    border-bottom: none;
  }
  
  
  /* For the definition list converted to flex  */
  [role=grid] > dl::after {
    content: "";
    margin: 0;
    padding: 0;
    display: block;
    clear: both;
  }
  .t3[role=grid] > * {
    display: flex;
    flex-wrap: nowrap;
  }
  .t3[role=grid] > * > * {
    flex: 1 0 1em;
  }
  .t3[role=grid] > * > *:first-child {
    flex: 1 0 3em;
  }
  [role=grid] > dl:not(:last-child) > * {
    border-bottom: none;
  }
  [role=grid] > dl > *:not(:last-child) {
    border-right: none;
  }
  
  /* For the definition list converted to table  */
  .t4[role=grid] > p {
    display: table-caption;
  }
  .t4[role=grid] {
    display: table;
  }
    .t4[role=grid] > * {
    display: table-row;
  }
    .t4[role=grid] > * > * {
    display: table-cell;
  }
  .t4[role=grid] > dl:not(:last-child) > * {
    border-bottom: none;
  }
  .t4[role=grid] > dl > *:not(:last-child) {
    border-right: none;
  }
  
  /* For the table */
  table {
    display: block;
  }
  table::after {
    content: "";
    margin: 0;
    padding: 0;
    display: block;
    clear: both;
  }
  th, td {
    display: block;
  }
  th {
    text-align: right;
  }
  tr {
    display: inline-block;
    float: left;
  }
  tr:not(:last-child) > td, tr:not(:last-child) > th {
    border-right: none;
  }
  tr > td:not(:last-child), tr > th:not(:last-child) {
    border-bottom: none;
  }
}


              
            
!

JS

              
                
              
            
!
999px

Console