123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <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>
            
          
!
            
              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;
}

            
          
!
            
              
 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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console