Header (My Books / Browse) has the wrong background color on /stats
Problem
On /stats, the header has the wrong background color. The header holds the "My Books" and "Browse" navigation. The header turns a cold grey. On every other page the header uses the paper tone. The grey clashes with the white content below it.
The bug appears at all widths. The header has no background of its own, so it shows the page canvas. The /stats page paints the page canvas grey.
Evidence
- URL: https://openlibrary.org/stats
Image
Reproducing the bug
- Open https://openlibrary.org/stats in a browser.
- Look at the header that holds "My Books" and "Browse".
- Expected behavior: The header has the same paper tone as the rest of the site.
- Actual behavior: The header is grey. It does not match other pages.
Context
- Browser (Chrome, Safari, Firefox, etc): any. The bug is CSS-only.
- OS (Windows, Mac, etc): any.
- Logged in (Y/N): no. Login state does not matter.
- Environment (prod, dev, local): prod
Breakdown
Implementation Details (for maintainers)
Cause
The /stats view renders the admin/index template. See class stats in openlibrary/views/loanstats.py (path /stats). That template sets the page CSS bundle to admin:
$ _x = ctx.setdefault('cssfile', 'admin')
openlibrary/templates/site/head.html then loads build/css/page-admin.css. That sheet repaints the page canvas grey:
body {
background-color: hsl(0, 0%, 73%);
}
div#background {
background-color: hsl(0, 0%, 83%);
}
The body rule overrides the default paper canvas (--color-background: var(--paper) in static/css/tokens/colors.css).
The header in openlibrary/templates/lib/nav_head.html has no background of its own. So it shows the body canvas. On every other page the body canvas is the paper tone, so the header matches the page. On /stats the canvas is grey, so the header shows grey.
lib/nav_head.html renders two header bars:
<header id="header-bar">— the main header. It holds "My Books" and "Browse" at widths of 960px and up.<header class="header-bar mobile">— a second row that holds "My Books" and "Browse" below 960px.
Below 960px the main header gets its own paper gradient. See the #header-bar rule in static/css/components/header-bar.css. The mobile bar has no background of its own. So it shows the grey canvas. At widths of 960px and up, neither bar has a background, so the grey canvas shows through the whole header row.
Fix direction
Make the header paint its own surface. Then the header no longer depends on the page canvas. Two options:
- Keep the grey canvas off the header. Scope the
admincanvas rule so it does not affect the global header. - Give the header its own paper surface. For example, apply the paper token or the existing gradient to
.header-barand.header-bar.mobile.
Confirm the fix at laptop, tablet, and mobile widths. The rest of /stats must keep the admin grey canvas. Keep the change scoped to the header surface.
Verify the fix at these points:
- The mobile bar still sits under the sticky header at widths below 960px.
- The header surface is not painted twice.
- Other pages keep the current look.
Related files
openlibrary/views/loanstats.py— the/statsview (class stats).openlibrary/templates/admin/index.html— setscssfiletoadmin.openlibrary/templates/site/head.html— loadsbuild/css/page-<cssfile>.css.static/css/page-admin.css— sets the greybodybackground.openlibrary/templates/lib/nav_head.html— renders the two header bars.static/css/components/header-bar.css— header surfaces and the mobile bar.static/css/tokens/colors.css—--color-background,--paper, and the gradient tokens.
Requirements Checklist
- [ ] The header on
/statsmatches the paper tone of other pages. - [ ] The "My Books / Browse" bar matches the header on
/statsat all widths. - [ ] The header still matches on other pages.
- [ ] The rest of
/statskeeps theadmingrey canvas. - [ ] The sticky header still works at widths below 960px.
Stakeholders
- @lokesh — lead for this front-end design-system issue.
Instructions for Contributors
- Please run these commands to ensure your repository is up to date before creating a new branch to work on this issue and each time after pushing code to Github, because the pre-commit bot may add commits to your PRs upstream.
Hi, I'd like to work on this, please assign it to me.
My understanding: /stats renders admin/index, which sets cssfile to admin, so page-admin.css loads and paints body (and div#background) grey. The header in lib/nav_head.html has no background of its own, so it shows that grey canvas instead of the paper tone used on other pages.
Proposed approach: keep the grey admin canvas for the page content, but give the header its own paper surface so it no longer depends on the body background. I'd do this in static/css/components/header-bar.css (for #header-bar and .header-bar.mobile), or scope the body rule in static/css/page-admin.css so it doesn't reach the header, whichever you prefer. I'd then check laptop, tablet and mobile widths, the sticky header below 960px, and a couple of other pages for regressions.
Question: .header-bar is capped at max-width: 1060px and centered, so painting only that element might leave grey strips at the sides on wide screens. Should the paper surface span the full width (e.g. on the wrapping element), or is it fine to scope the admin canvas rule instead?
Hi @lokesh !
I traced why the header turns grey on /stats, and I'd like to ask which fix you'd prefer before I open a PR.
Side finding
Both openlibrary/static/css/page-admin.css (line 106) and openlibrary/static/css/page-user.css (line 73) have a div#background rule. I couldn't find an element with that id in the templates or JS, so these rules look like leftovers from the old layout. I only searched openlibrary/templates, the openlibrary JS plugin folder and static/css, so please correct me if something else emits it.
Options
- A. Remove the admin grey. Delete the
bodyrule (and the deaddiv#backgroundrules)./statsgets the normal canvas. It's the smallest change, but all admin pages lose the grey look. - B. Move the grey from
bodytomain. The header and footer stay on the normal canvas, and only the content area is grey. It keeps the admin look, but I'd need to check thatmainis full width, and the hardcodedhsl()should become a token. - C. Paint the header with its own surface. This is the approach suggested earlier in the thread. The header is capped at
max-width: 1060px, so on wide screens grey strips would remain on both sides. There are also two header elements (#header-barand.header-bar.mobile) to cover. - D. Stop
/statsfrom using the admin stylesheet./statsis a public page, so it could get its own stylesheet. This is the cleanest long-term fix, but it's bigger and I wouldn't recommend it for a quick fix, the two-column layout and the stats table and graph styles live inpage-admin.css, so they'd have to move to a new file.
Which would you prefer? I'm happy to discuss and work on some other approaches as well.
P.S. Unrelated: docs/frontend/css.md still refers to site.html, which became shell/head.html.jinja and core/shell/head.py in #13703. I can update the docs in a separate PR.
Hi @lokesh @RayBB,
I’ve evaluated an answer for this problem locally.
Rather than applying background styles to .header-bar (which has max-width: 1060px and creates grey gutters on larger screens), the better solution is to restrict the admin canvas in static/css/page-admin.css to `` instead ofbody.
With this method, the global header properly uses standard paper canvas at all screen resolutions (the /stats dashboard page continues to have required admin grey canvas) and the old div#background rule is removed.
Could you assign me this issue? I’ve checked the solution on desktop (1440px), tablet (768px), and mobile (375px) and I would like to create a PR with before and after screenshots.
Thanks all! Let's go with @Ved-sketch's Option A: just remove the admin body grey (and the dead div#background rules in page-admin.css and page-user.css). Simplest fix, and we can find another way to distinguish admin pages later if we need to. @Ved-sketch, it's yours. Separate PR for the docs/frontend/css.md fix sounds good too.