Skip to content

Commit c01398d

Browse files
committed
Add scroll to tables
1 parent de40fd6 commit c01398d

1 file changed

Lines changed: 62 additions & 48 deletions

File tree

css/styles.css

Lines changed: 62 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
padding: 0.5em 1em;
1919
border-radius: 5px;
2020
margin-bottom: 1em;
21+
max-width: 100%;
22+
overflow-x: auto;
23+
}
24+
25+
/* Strip the gray box from cell outputs that contain a table —
26+
the table's own scroll container handles border + shadow */
27+
28+
.cell-output-display:has(table) {
29+
background-color: transparent !important;
30+
padding: 0 !important;
31+
border-radius: 0;
32+
box-shadow: none;
2133
}
2234

2335
/* ============================================================
@@ -203,18 +215,16 @@ img {
203215
}
204216

205217
/* ============================================================
206-
TABLES: AESTHETICS ONLY
218+
TABLES: AESTHETICS
207219
============================================================ */
208220

209221
/* Alternating row shading */
210222

211-
table tr:nth-child(even) {
212-
background-color: #f5f5f5;
213-
}
223+
table tr:nth-child(even) { background-color: #f5f5f5; }
224+
table tr:nth-child(odd) { background-color: #ffffff; }
214225

215-
table tr:nth-child(odd) {
216-
background-color: #ffffff;
217-
}
226+
/* Hover row highlight */
227+
table tbody tr:hover { background-color: #fdf0f2; }
218228

219229
/* Cell padding and borders */
220230

@@ -225,23 +235,30 @@ table td {
225235
text-align: left;
226236
}
227237

228-
/* Crimson header with rounded top corners and white text */
238+
/* Table base.
239+
border-collapse: collapse (not separate) is required for
240+
position: sticky on thead th to work correctly.
241+
border-radius and box-shadow are applied to the scroll
242+
containers below instead of the table element itself. */
229243

230244
table {
231-
border-collapse: separate; /* required for border-radius on thead to work */
245+
border-collapse: collapse;
232246
border-spacing: 0;
233-
border: 1px solid #d0d0d0;
234-
border-radius: 6px;
235-
overflow: hidden; /* clips corners cleanly */
236247
background: #fff;
237-
box-shadow: 0px 2px 5px rgba(0,0,0,0.08);
238248
}
239249

250+
/* Crimson sticky header.
251+
box-shadow replaces border-bottom because border-collapse: collapse
252+
causes cell borders on sticky elements to visually disappear mid-scroll. */
253+
240254
table thead th {
241255
background-color: #a51c30 !important;
242256
color: #ffffff !important;
243257
font-weight: 700 !important;
244-
border-color: #8b1628 !important;
258+
position: sticky;
259+
top: 0;
260+
z-index: 2;
261+
box-shadow: inset 0 -2px 0 #8b1628;
245262
}
246263

247264
/* ============================================================
@@ -315,23 +332,18 @@ figure figcaption {
315332
}
316333

317334
/* ============================================================
318-
TABLE LAYOUT: WRAPPING + SCROLLING
335+
TABLE LAYOUT: SCROLLING + NO SQUASHING
319336
============================================================ */
320337

321338
/*
322-
Strategy:
323-
- col { width: auto } neutralises Quarto's inline <col style="width: X%">
324-
which otherwise crushes narrow columns regardless of their content.
325-
- table-layout: auto + width: max-content tells the browser to size the
326-
table and each column purely by content. Short columns stay narrow,
327-
long ones get the space they need. No column ever squashes another.
328-
- Text wraps naturally in cells that genuinely have long content.
329-
Cells with short content (<~30 chars) won't wrap because the column
330-
will simply be wide enough to fit them on one line.
331-
- min-width: 80px on cells ensures no column collapses to unreadable.
332-
- The scroll container is div[aria-describedby] inside figure.quarto-float-tbl.
333-
The figure and its outer div are forced to display:block (not flex) so
334-
the scroll boundary starts at the true left edge of the table.
339+
Changes from previous version:
340+
─ white-space: nowrap replaces normal + overflow-wrap + word-break
341+
PRIMARY fix for the squashed/crushed look
342+
─ max-height + overflow-y: auto on containers → vertical scroll
343+
like kableExtra's scroll_box
344+
─ border-radius + box-shadow moved from table → scroll containers
345+
(they must live on the scroll container, not the table, for
346+
sticky headers to work)
335347
*/
336348

337349
/* 1. Neutralise Quarto's inline colgroup percentages */
@@ -347,23 +359,22 @@ table {
347359
width: max-content;
348360
}
349361

350-
/* 3. Cell text: wrap only when content is genuinely long */
362+
/* 3. Cell text: nowrap is the primary fix for squashing */
351363

352364
table th,
353365
table td {
354-
white-space: normal;
355-
overflow-wrap: break-word;
356-
word-break: break-word;
357-
min-width: 80px;
366+
white-space: nowrap;
367+
min-width: 60px;
358368
}
359369

360370
/* 4. Scroll containers for Quarto captioned tables (#tbl-*)
361371
Structure:
362-
div.quarto-float <- display:block
363-
figure.quarto-float-tbl <- display:block (NOT flex)
364-
figcaption
365-
div[aria-describedby] <- overflow-x:auto lives here
366-
table <- margins zeroed; width:max-content */
372+
div.cell-output-display <- transparent (overridden above)
373+
div.quarto-float <- display:block
374+
figure.quarto-float-tbl <- display:block (NOT flex)
375+
figcaption
376+
div[aria-describedby] <- scroll box + border lives here
377+
table <- margins zeroed; width:max-content */
367378

368379
div.quarto-float:has(figure.quarto-float-tbl) {
369380
display: block !important;
@@ -383,27 +394,31 @@ figure.quarto-float-tbl {
383394
figure.quarto-float-tbl > div[aria-describedby] {
384395
display: block;
385396
width: 100%;
397+
max-height: 450px;
386398
overflow-x: auto;
399+
overflow-y: auto;
387400
-webkit-overflow-scrolling: touch;
388401
box-sizing: border-box;
402+
border: 1px solid #d0d0d0;
403+
border-radius: 6px;
404+
box-shadow: 0px 2px 5px rgba(0,0,0,0.08);
389405
}
390406

391407
figure.quarto-float-tbl > div[aria-describedby] > table {
392408
margin-left: 0;
393409
margin-right: 0;
394410
}
395411

396-
/* 5. Scroll container for Pandas DataFrames (cell output) */
412+
/* 5. Scroll container for Pandas DataFrames (bare cell output) */
397413

398-
.cell-output-display {
399-
max-width: 100% !important;
400-
overflow-x: auto !important;
414+
.cell-output-display:has(table.dataframe) {
415+
max-height: 450px;
416+
overflow-x: auto;
417+
overflow-y: auto;
401418
-webkit-overflow-scrolling: touch;
402-
}
403-
404-
.cell-output-display > div {
405-
max-width: 100% !important;
406-
overflow-x: auto !important;
419+
border: 1px solid #d0d0d0;
420+
border-radius: 6px;
421+
box-shadow: 0px 2px 5px rgba(0,0,0,0.08);
407422
}
408423

409424
.cell-output-display table.dataframe,
@@ -419,7 +434,6 @@ figure.quarto-float-tbl > div[aria-describedby] > table {
419434
Error message handling
420435
============================================================ */
421436

422-
423437
/* Make long error messages scroll instead of stretching the page */
424438
.cell-output-stderr pre,
425439
.cell-output-stdout pre,

0 commit comments

Comments
 (0)