Problem: Adaptive Data Table
Problem description
You have a <div class="table-wrapper"> containing a <table> with <thead> and <tbody> rows and cells. Write CSS so that:
.table-wrapperdeclarescontainer-type: inline-size.Large (≥800px): The
<table>usesdisplay: tablewithgrid-template-columnssemantics emulated viatable-layout: fixedand column widths defined byminmax(150px, max-content),2fr,fit-content(200px), and1frrespectively.Medium (400px–799px): The
<table>hides its header and setsdisplay: gridon each<tr>withgrid-template-areasto display cells in a 2×2 card layout.Small (<400px): The
<table>displays each<tr>asdisplay: flex; flex-direction: column;with each<td>rendered as ablockcontaining itsdata-label(the corresponding<th>text) and value side by side.
Goal
Implement CSS in styles.css to:
Configure the table wrapper as a container for inline sizing.
Use
@containerqueries at 400px and 800px to switch between table, grid, and flex layouts.Apply CSS Grid intrinsic sizing functions for large and medium layouts.
Leverage
content: attr(data-label)to display headers in small view.
Constraints
Do not modify the HTML structure except for adding
data-labelattributes to<td>elements.Use only CSS (no JavaScript).
Define breakpoints exactly at 400px and 800px.
Ensure no layout introduces horizontal overflow.
Sample visual output
Here’s what the output would look like:
Good luck trying the problem! If you’re unsure how to proceed, check the Solution.
Problem: Adaptive Data Table
Problem description
You have a <div class="table-wrapper"> containing a <table> with <thead> and <tbody> rows and cells. Write CSS so that:
.table-wrapperdeclarescontainer-type: inline-size.Large (≥800px): The
<table>usesdisplay: tablewithgrid-template-columnssemantics emulated viatable-layout: fixedand column widths defined byminmax(150px, max-content),2fr,fit-content(200px), and1frrespectively.Medium (400px–799px): The
<table>hides its header and setsdisplay: gridon each<tr>withgrid-template-areasto display cells in a 2×2 card layout.Small (<400px): The
<table>displays each<tr>asdisplay: flex; flex-direction: column;with each<td>rendered as ablockcontaining itsdata-label(the corresponding<th>text) and value side by side.
Goal
Implement CSS in styles.css to:
Configure the table wrapper as a container for inline sizing.
Use
@containerqueries at 400px and 800px to switch between table, grid, and flex layouts.Apply CSS Grid intrinsic sizing functions for large and medium layouts.
Leverage
content: attr(data-label)to display headers in small view.
Constraints
Do not modify the HTML structure except for adding
data-labelattributes to<td>elements.Use only CSS (no JavaScript).
Define breakpoints exactly at 400px and 800px.
Ensure no layout introduces horizontal overflow.
Sample visual output
Here’s what the output would look like:
Good luck trying the problem! If you’re unsure how to proceed, check the Solution.