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 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

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

              
                <table class="has-4-col" id="table_1">
    <caption id="title_table_1">
      Variation on <a href="http://adrianroselli.com/2017/11/a-responsive-accessible-table.html#Example">Adrian Roselli's responsive tables</a>
    </caption>
        <thead>
            <tr>
                <th scope="col">Lieu</th>
                <th scope="col">Objet un titre de cellule extrêmement long</th>
                <th scope="col" class="droite">Loyer</th>
                <th scope="col">Quartier</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><a href="#">Chemin du Château-Bloch 19</a></td>
                <td>Bureau</td>
                <td class="droite">6183.00</td>
                <td>Vernier</td>
            </tr>
            <tr>
                <td><a href="#">Chemin du Château-Bloch 19</a></td>
                <td>Bureau</td>
                <td class="droite">6183.00</td>
                <td>Vernier</td>
            </tr>
            <tr>
                <td><a href="#">Chemin du Château-Bloch 19</a></td>
                <td>Bureau</td>
                <td class="droite">6183.00</td>
                <td>Vernier</td>
            </tr>
            <tr>
                <td><a href="#">Chemin du Château-Bloch 19</a></td>
                <td>Bureau</td>
                <td class="droite">6183.00</td>
                <td>Vernier</td>
            </tr>
            <tr>
                <td><a href="#">Chemin du Château-Bloch 19</a></td>
                <td>Bureau</td>
                <td class="droite">6183.00</td>
                <td>Vernier Vernier Vernier Vernier Vernier Vernier Vernier Vernier Vernier Vernier</td>
            </tr>
            <tr>
                <td><a href="#">Chemin du Château-Bloch 19 Chemin du Château-Bloch 19</a></td>
                <td>Bureau</td>
                <td class="droite">6183.00</td>
                <td>Vernier</td>
            </tr>
            <tr>
                <td><a href="#">Chemin du Château-Bloch 19</a></td>
                <td>Bureau</td>
                <td class="droite">6183.00</td>
                <td>Vernier</td>
            </tr>
            <tr>
                <td><a href="#">Chemin du Château-Bloch 19 Chemin du Château-Bloch 19</a></td>
                <td>Bureau</td>
                <td class="droite">6183.00</td>
                <td>Vernier Vernier Vernier Vernier Vernier Vernier Vernier Vernier Vernier Vernier</td>
            </tr>
            <tr>
                <td><a href="#">Quai du Seujet 34</a></td>
                <td>Arcade</td>
                <td class="droite">2875.00</td>
                <td>Grottes Saint-Gervais</td>
            </tr>
        </tbody>
    </table>
              
            
!

CSS

              
                table {
  width: 40%;
}
thead {
  display:none;
}
caption {
  text-align:left;
  font-weight: bold;
}
tr {

  margin-left: 20%;
  margin-bottom:1em;
  border-top: 2px darkgray solid;
  border-bottom: 2px darkgray solid;
}

tr, td, th {
  display:block;
}

td {
  background:lightgray;
  padding:0.5em 0;
  border-bottom: 1px white solid;
  padding-left: 0.5em;

}
td:last-child {
  border-bottom: none;
}
td::before {
  position: absolute;
  left: 0;
  hyphens: auto;
  width: 8%;
  display:block;
  padding-right: 0.5em;
  font-weight: bold;
  text-align: right;
}

              
            
!

JS

              
                
 function ResponsiveCellHeaders(elmID) {
  try {
    var THarray = [];
    var table = document.getElementById(elmID);
    var ths = table.getElementsByTagName("th");
    for (var i = 0; i < ths.length; i++) {
      var headingText = ths[i].innerHTML;
      THarray.push(headingText);
    }
    var styleElm = document.createElement("style"),
      styleSheet;
    document.head.appendChild(styleElm);
    styleSheet = styleElm.sheet;
    for (var i = 0; i < THarray.length; i++) {
      styleSheet.insertRule(
        "#" +
          elmID +
          " td:nth-child(" +
          (i + 1) +
          ')::before {content:"' +
          THarray[i] +
          ': ";}',
        styleSheet.cssRules.length
      );
    }
  } catch (e) {
    console.log("ResponsiveCellHeaders(): " + e);
  }
}

function adjustCellHeight(tbl) {
  var tds=tbl.getElementsByTagName("td");
  console.log(tds.length);
    for (var i = 0, len = tds.length; i < len; i++) {

      tds[i].style.setProperty('height', Math.max(parseInt(getHeight(tds[i], ":before")), parseInt(getHeight(tds[i])))+"px");
     
  }
}
function getHeight(elt, pseudoElt) {
    return(window.getComputedStyle(elt, pseudoElt).getPropertyValue('height'));
}


ResponsiveCellHeaders("table_1");
adjustCellHeight(document.getElementById("table_1"));
function AddTableARIA() {
  try {
    var allTables = document.querySelectorAll('table');
    for (var i = 0; i < allTables.length; i++) {
      allTables[i].setAttribute('role','table');
    }
    var allRowGroups = document.querySelectorAll('thead, tbody, tfoot');
    for (var i = 0; i < allRowGroups.length; i++) {
      allRowGroups[i].setAttribute('role','rowgroup');
    }
    var allRows = document.querySelectorAll('tr');
    for (var i = 0; i < allRows.length; i++) {
      allRows[i].setAttribute('role','row');
    }
    var allCells = document.querySelectorAll('td');
    for (var i = 0; i < allCells.length; i++) {
      allCells[i].setAttribute('role','cell');
    }
    var allHeaders = document.querySelectorAll('th');
    for (var i = 0; i < allHeaders.length; i++) {
      allHeaders[i].setAttribute('role','columnheader');
    }
    // this accounts for scoped row headers
    var allRowHeaders = document.querySelectorAll('th[scope=row]');
    for (var i = 0; i < allRowHeaders.length; i++) {
      allRowHeaders[i].setAttribute('role','rowheader');
    }
    // caption role not needed as it is not a real role and
    // browsers do not dump their own role with display block
  } catch (e) {
    console.log("AddTableARIA(): " + e);
  }
}

AddTableARIA();

              
            
!
999px

Console