Merge pull request 'Show navbar on hover/keyboard focus' (#106) from hidden-nav into main

Reviewed-on: https://codeberg.org/daudix/duckquill/pulls/106
This commit is contained in:
David Lapshin
2024-10-28 03:47:53 +00:00
5 changed files with 84 additions and 24 deletions

View File

@ -179,6 +179,8 @@ csp = [
# debug_no_styles = true # debug_no_styles = true
[extra.nav] [extra.nav]
# Whether to automatically hide nav when not hovered or focused
auto_hide = true
# Whether to show the Atom/RSS feed button in the nav # Whether to show the Atom/RSS feed button in the nav
show_feed = true show_feed = true
# Whether to show the manual theme switcher in the nav # Whether to show the manual theme switcher in the nav

View File

@ -20,18 +20,15 @@
} }
& + #heading { & + #heading {
margin-block-start: 35vw; margin-block-start: calc(50vw - 8.75rem);
} }
@media only screen and (max-width: 480px) { @media only screen and (max-width: 480px) {
body:has(&) #site-nav { body:has(&) #site-nav:not(#handle + #site-nav) {
margin-block-start: 50vw; margin-block-start: calc(50vw + 1rem);
}
} }
& + #heading {
margin-block-start: 2rem;
}
}
} }
#heading { #heading {

View File

@ -65,7 +65,7 @@ body {
} }
.container { .container {
margin: 0 auto; margin: 4.25rem auto 0;
width: min(var(--container-width), 90%); width: min(var(--container-width), 90%);
} }

View File

@ -1,15 +1,76 @@
#handle {
position: fixed;
z-index: 1;
transition: var(--transition);
margin: 0 auto;
inset-block-start: 1rem;
inset-inline-end: 0;
inset-inline-start: 0;
width: min(var(--container-width), 90%);
height: 3.25rem;
&::before {
position: absolute;
transition: var(--transition);
margin: 0 auto;
inset-block-start: 0;
inset-inline-end: 0;
inset-inline-start: 0;
box-shadow: var(--edge-highlight);
border-radius: 999px;
background-color: var(--fg-muted-2);
width: 50%;
height: 0.5rem;
content: "";
}
&:hover::before,
&:has(+ #site-nav:hover)::before,
&:has(+ #site-nav *:focus-visible, + #site-nav *:focus)::before {
transform: translateY(-1rem) scale(0.5);
opacity: 0;
}
&:hover + #site-nav {
transform: none;
opacity: 1;
}
& + #site-nav {
position: fixed;
transform: translateY(-1rem) scale(0.5);
transform-origin: top;
opacity: 0;
transition: var(--transition);
margin: 0 auto;
width: max-content;
nav {
pointer-events: none;
}
&:hover,
&:has(*:focus-visible, *:focus) {
transform: none;
opacity: 1;
nav {
pointer-events: all;
}
}
}
}
#site-nav { #site-nav {
position: sticky; position: sticky;
left: 50%;
z-index: 999; z-index: 999;
margin: 1rem auto; margin: 1rem auto 0;
inset-block-start: 1rem; inset-block-start: 1rem;
inset-inline-end: 0;
inset-inline-start: 0;
border-radius: 1.625rem; border-radius: 1.625rem;
max-width: 90%; max-width: min(var(--container-width), 90%);
@media only screen and (max-width: 480px) {
position: relative;
inset-block-start: 0;
}
&::before { &::before {
-webkit-backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
@ -362,13 +423,11 @@
} }
#search-results { #search-results {
--mask: linear-gradient( --mask: linear-gradient(to bottom,
to bottom,
transparent, transparent,
black 1rem, black 1rem,
black calc(100% - 1rem), black calc(100% - 1rem),
transparent transparent);
);
-webkit-mask-image: var(--mask); -webkit-mask-image: var(--mask);
display: none; display: none;
flex: 1; flex: 1;
@ -404,8 +463,7 @@
&:first-of-type, &:first-of-type,
&.more-matches { &.more-matches {
margin-block-start: 0.5rem; margin-block-start: 0.5rem;
border-block-start: max(1px, 0.0625rem) solid border-block-start: max(1px, 0.0625rem) solid var(--fg-muted-2);
var(--fg-muted-2);
padding-block-start: 0.25rem; padding-block-start: 0.25rem;
} }

View File

@ -1,5 +1,8 @@
{%- set rel_attributes = macros_rel_attributes::rel_attributes() | trim -%} {%- set rel_attributes = macros_rel_attributes::rel_attributes() | trim -%}
{%- if config.extra.nav.auto_hide %}
<div id="handle"></div>
{%- endif %}
<header id="site-nav"> <header id="site-nav">
<nav> <nav>
<a href="#main" id="main-content" tabindex="0"> <a href="#main" id="main-content" tabindex="0">