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

              
                <section class="section">
<div class="w-richtext">

  
<table>
  <thead>
    <tr>
      <th>Feature / Platform</th>
      <th>AlphaOne</th>
      <th>BetaSphere</th>
      <th>GammaTech</th>
      <th>DeltaWave</th>
      <th>EpsilonBase</th>
      <th>ZetaFlow</th>
      <th>EtaField</th>
      <th>ThetaZone</th>
      <th>IotaStream</th>
      <th>KappaPort</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Real-time Analytics</td>
      <td>Yes</td>
      <td>No</td>
      <td>Yes</td>
      <td>No</td>
      <td>Yes</td>
      <td>No</td>
      <td>Yes</td>
      <td><svg>...</svg></td>
      <td>No</td>
      <td>Yes</td>
    </tr>
    <tr>
      <td>Cloud Integration</td>
      <td>No</td>
      <td>Yes</td>
      <td>No</td>
      <td><svg>...</svg></td>
      <td>No</td>
      <td>Yes</td>
      <td>No</td>
      <td>Yes</td>
      <td>No</td>
      <td><svg>...</svg></td>
    </tr>

  </tbody>
</table>







  
</div>
</section>
              
            
!

CSS

              
                
table {
  border-collapse: collapse;
  width: 100%;
}

th, td {
  border: 1px solid #ccc; /* Change color as needed */
  text-align: left;
  padding: 8px;
}

th {
  background-color: #f2f2f2; /* Gives a distinct look to header cells */
}


/* Initially hide the mobile tables container */
.mobile-tables-container {
  display: none;
}

/* Hide the original table on mobile */
@media (max-width: 991px) { /* Adjust the breakpoint as needed */
  .desktop-table {
    display: none;
  }

  .mobile-tables-container {
    display: block;
  }
}

/* Show the original table on desktop */
@media (min-width: 992px) {
  .mobile-tables-container {
    display: none;
  }

  .desktop-table {
    display: table;
  }
}

              
            
!

JS

              
                document.addEventListener('DOMContentLoaded', function() {
  const tables = document.querySelectorAll('.w-richtext table');

  tables.forEach(originalTable => {
    // Clone the original table
    const clonedTable = originalTable.cloneNode(true);

    // Create a container for the mobile-friendly tables
    const mobileTablesContainer = document.createElement('div');
    mobileTablesContainer.className = 'mobile-tables-container';

    // Extract headers
    const headers = Array.from(originalTable.querySelectorAll('thead th')).map(th => th.textContent);

    // Process each row in the cloned table
    Array.from(clonedTable.querySelectorAll('tbody tr')).forEach(row => {
      const mobileTable = document.createElement('table');
      mobileTable.className = 'mobile-table';

      // For each cell in the row, create a new row in the mobile table with the header and the cell data
      Array.from(row.cells).forEach((cell, index) => {
        const newRow = mobileTable.insertRow();
        const headerCell = newRow.insertCell();
        headerCell.textContent = headers[index];
        const dataCell = newRow.insertCell();
        dataCell.textContent = cell.textContent;
      });

      mobileTablesContainer.appendChild(mobileTable);
    });

    // Hide the original table on mobile
    originalTable.classList.add('desktop-table');

    // Insert the mobile tables container after the original table
    originalTable.parentNode.insertBefore(mobileTablesContainer, originalTable.nextSibling);
  });
});

              
            
!
999px

Console