diff --git a/assets/scss/_a11y.scss b/assets/scss/_a11y.scss new file mode 100644 index 0000000..12c3568 --- /dev/null +++ b/assets/scss/_a11y.scss @@ -0,0 +1,42 @@ +@use '@/assets/scss/layout'; + +/** + * Visually hide an element and leave it only for screenreaders + */ +@mixin screen-reader-only { + border: 0; + clip: rect(0, 0, 0, 0); + height: 1px; + margin: -1px; + overflow: hidden; + padding: 0; + position: absolute; + width: 1px; +} + +/** + * Sets initial styles for the 'Skip to content' link; hidden until it has focus. + */ +@mixin skip-link { + @include layout.auto-margins; + background-color: #fff; + color: inherit; + left: 0; + opacity: 0; + overflow: hidden; + padding: rem(10); + position: absolute; + right: 0; + text-align: center; + text-decoration: none; + top: 0; + transform: translateY(-100%); + width: max-content; + z-index: -1; + + &:focus { + opacity: 1; + transform: translateY(0); + z-index: 2147483647; // Theoretical max. + } +} diff --git a/assets/scss/_layout.scss b/assets/scss/_layout.scss new file mode 100644 index 0000000..789da46 --- /dev/null +++ b/assets/scss/_layout.scss @@ -0,0 +1,9 @@ +// Layout-related mixins go here. + +/** + * Centered block. + */ +@mixin auto-margins { + margin-left: auto; + margin-right: auto; +} diff --git a/entries/global/index.scss b/entries/global/index.scss index d244692..4ce87f6 100644 --- a/entries/global/index.scss +++ b/entries/global/index.scss @@ -18,4 +18,13 @@ global entry styles. */ +@use '@/assets/scss/a11y'; @use '@/assets/scss/normalize' as *; + +.screen-reader-text { + @include a11y.screen-reader-only; +} + +.skip-link { + @include a11y.skip-link; +} diff --git a/parts/header.html b/parts/header.html index 0d244d6..92605cd 100644 --- a/parts/header.html +++ b/parts/header.html @@ -1,3 +1,4 @@ +