You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Scroll down a bit so that there is some page content behind the navbar.
Open DevTools and set --vp-c-bg: darkslategray; on the html element.
Result: the background color of the navbar and of the page content don't match.
Expected behavior
The background color of the navbar and of the page content should match.
So far I've worked around this issue with this CSS:
/* * Fix hardcoded background color of the Nav component. * Needs to be a color that matches --vp-c-bg but with partial opacity (for the glass effect). */@media (min-width:960px) {
:root.dark .VPNav.no-sidebar,:root.dark .VPNavBar.has-sidebar .content {
background-color:hsl(22014%13%/0.7);
}
}
I haven't found a CSS fix where the opaque --vp-c-bg variable can be used directly. Using a pseudo-element to make a fake background doesn't seem to work, though maybe I’m missing a trick.
My suggestion is to introduce a CSS variable that is either generic or specific to the navbar, something like:
This second option might be used by people who want to opt out of the glass effect, by setting it to --vp-nav-glass-bg: var(--vp-c-bg); (though I have not confirmed that using an opaque color removes the perf issues described in #1049).
It might also be possible to compute a background color by defaulting to using --vp-c-bg first (opaque), then at runtime use getComputedStyle(element).getPropertyValue('background-color'), parse the result and add 0.7 opacity.
System Info
[Not relevant here. See the reproduction steps, which use the production Vitepress docs.]
Describe the bug
The VPNavBar component sets a background-color on one of its containers with a
rgba()
value that is not inherited from the theme's CSS variables.As a result if you customize the value of
--vp-c-bg
(shown behind the navbar), you end up with mismatched colors.Reproduction
--vp-c-bg: darkslategray;
on thehtml
element.Result: the background color of the navbar and of the page content don't match.
Expected behavior
The background color of the navbar and of the page content should match.
So far I've worked around this issue with this CSS:
I haven't found a CSS fix where the opaque
--vp-c-bg
variable can be used directly. Using a pseudo-element to make a fake background doesn't seem to work, though maybe I’m missing a trick.My suggestion is to introduce a CSS variable that is either generic or specific to the navbar, something like:
or more specific to the navbar:
This second option might be used by people who want to opt out of the glass effect, by setting it to
--vp-nav-glass-bg: var(--vp-c-bg);
(though I have not confirmed that using an opaque color removes the perf issues described in #1049).It might also be possible to compute a background color by defaulting to using
--vp-c-bg
first (opaque), then at runtime usegetComputedStyle(element).getPropertyValue('background-color')
, parse the result and add 0.7 opacity.System Info
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: