CHROMATIC-SYSTEM v1.03_EXPANDING_TABLE_ROWS_DISPLAY_ENGINE

INFORMATION & CODE

Expanding Table Rows Display

What the Code Does

This code creates an interactive, retro-styled HTML table that functions like an accordion. It displays a list of children with their names and birth order (Peter, Louis, and Stephen). Each main row acts as a clickable button; when clicked, it toggles the visibility of an associated hidden row beneath it. This hidden row expands to reveal detailed biographical or comparative information about that specific child's age relative to the others. The page is styled using custom retro gaming fonts (Google Fonts "Press Start 2P" and "VT323"), colorful gradients, and rounded borders, making the data presentation playful and visually engaging.

How The Code Works

The functionality is split across three standard web technologies:

  • HTML Structure: The page contains a <table> element with a header ( <th>) and alternating rows (<tr>). The rows containing the children's names are given the class btn, a unique numeric id (0, 1, and 2), and an onclick attribute that triggers a JavaScript function. Directly below each clickable row is a detail row with the class tr and a single table cell (<td>) spanning all four columns (colspan="4").
  • CSS Styling: The stylesheet centers the table on the viewport using Flexbox. It uses retro font families, linear color gradients, and inner box-shadows to give the table cells a glossy, button-like appearance. Crucially, the CSS sets .tr { visibility: collapse; }, which hides the detail rows by default and ensures they don't take up any layout space until activated. A media query is also included to adjust the sizing for smaller mobile screens.
  • JavaScript Logic: The script first selects all elements with the .tr class and stores them in a NodeList variable called trow. When a user clicks a child's row, the uncollapse(inc) function is executed, passing the row's ID as an index (inc). The function checks the current visibility of the corresponding detail row. If it is currently "visible" , the script changes it to "collapse" to hide it; otherwise, it changes it to "visible" to reveal the hidden text. Clicking the row again toggles it back closed.

How to Use the Code

To use this code on your own website or local environment, follow these steps:

  1. Set Up Files: Create three separate files in the same folder on your computer: name them index.html, styles.css, and scripts.js.
  2. Paste the Code: Copy the HTML code into index.html, the CSS code into styles.css, and the JavaScript code into scripts.js. (Note: Ensure your local file names match the external links in the HTML <head> and <body> tags).
  3. Run the Page: Open the index.html file in any modern web browser by double- clicking it or dragging it into your browser window.
  4. Customize the Content:
    • To change the people listed, edit the text inside the <td> elements in index.html.
    • To add more rows, ensure you follow the pattern: create a clickable row (tr) with a sequential id (onclick="uncollapse(this.id)"), followed immediately by a detail row (tr class="tr") containing your expanded text.

HTML

CSS

JAVASCRIPT

PREVIEW

Child â„– First name Middle name Surname
1st Child Peter Thomas Griffin
Peter is older than Louis by 3 years, 11 months, 13 days. Peter is older than Stephen by 6 years, 9 months, 24 days.
2nd Child Louis Michael Hannant
Louis is youger than Peter by 3 years 11 months 13 days. Louis is older than Stephen by 2 years 10 months 13 days.
3rd Child Stephen David wright
Stephen is youger than Peter by 6 years 9 months 24 days. Stephen is younger than Louis by 2 years 10 months 13 days.