scrollbar.css 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Scrollbar skin: the sole consumer of the four --dsw-alias-scrollbar-*
  2. * tokens. Without it every scrolling region renders the UA scrollbar, which
  3. * ignores the theme — a light native bar over the dark palette.
  4. *
  5. * The rules sit on `body`, not `html`: design-platform.css declares the
  6. * --dsw-alias-* tokens on `body` (and the dark overrides on
  7. * `body[data-ds-dark-theme]`), and custom properties only inherit downward,
  8. * so an `html` rule resolves them to the guaranteed-invalid value and
  9. * `scrollbar-color` falls back to `auto`.
  10. *
  11. * Surfaces pick their elevation by rebinding --dsh-scrollbar-thumb{,-hover}:
  12. * the l1 pair here is the base-surface default, and an elevated surface
  13. * (menu, popover, dialog) rebinds to the l2 pair on its own container. Both
  14. * rendering paths below read the indirection, so one rebind reaches whichever
  15. * path the engine took. */
  16. body {
  17. --dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l1);
  18. --dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l1);
  19. }
  20. /* The two paths are mutually exclusive, and the gate is load-bearing rather
  21. than defensive. A non-`auto` `scrollbar-width` or `scrollbar-color` makes
  22. Chromium and Safari drop every `::-webkit-scrollbar*` rule for that
  23. element, including `::-webkit-scrollbar-thumb:hover` — measured in chromium
  24. as an 8px `::-webkit-scrollbar` width taking effect on its own and being
  25. ignored as soon as `scrollbar-width: thin` is added. Declaring both
  26. unconditionally therefore leaves the hover tokens with no rendering at all,
  27. because the engines that implement the hover pseudo-element are exactly the
  28. ones the standard properties silence, and Firefox has no hover
  29. pseudo-element to fall back on.
  30. `not selector(::-webkit-scrollbar)` is true only where the pseudo-element
  31. is unimplemented, so Firefox takes the standard path and WebKit-based
  32. engines take the pseudo-element path. An engine too old for the
  33. `selector()` function makes the condition invalid, which evaluates false
  34. and selects the pseudo-element path — the correct side for the pre-16.4
  35. Safari that is the realistic case. */
  36. @supports not selector(::-webkit-scrollbar) {
  37. /* Declared on every element rather than inherited from `body`. Inheriting
  38. would pass down the COLOUR already substituted at `body`, so a descendant
  39. rebinding --dsh-scrollbar-thumb could not change it; re-declaring makes
  40. each element substitute the variable as it sees it, which is what gives
  41. an elevated surface a working rebind. `scrollbar-width` is not an
  42. inherited property at all, so it needs the per-element declaration
  43. regardless.
  44. No hover counterpart exists on this path: `scrollbar-color` states one
  45. thumb colour and the engine derives its own hover treatment. */
  46. body,
  47. body * {
  48. scrollbar-width: thin;
  49. scrollbar-color: var(--dsh-scrollbar-thumb) transparent;
  50. }
  51. }
  52. /* Not gated in turn: an engine that does not implement these pseudo-elements
  53. drops the rules as unknown selectors, so the gate would only restate what
  54. selector matching already does. Not inherited either, hence the unscoped
  55. selectors. */
  56. ::-webkit-scrollbar {
  57. width: 8px;
  58. height: 8px;
  59. }
  60. /* Track stays transparent so the thumb reads against whatever surface scrolls
  61. under it; only the thumb carries a token colour. */
  62. ::-webkit-scrollbar-track {
  63. background: transparent;
  64. }
  65. ::-webkit-scrollbar-thumb {
  66. border-radius: 4px;
  67. background: var(--dsh-scrollbar-thumb);
  68. }
  69. ::-webkit-scrollbar-thumb:hover {
  70. background: var(--dsh-scrollbar-thumb-hover);
  71. }
  72. /* Both scrollbars meeting in a corner: no separate token, so the corner
  73. matches the transparent track rather than the UA's opaque default. */
  74. ::-webkit-scrollbar-corner {
  75. background: transparent;
  76. }