Skip to content

Instantly share code, notes, and snippets.

@MrGrigri
Last active October 19, 2022 23:20
Show Gist options
  • Save MrGrigri/907466afd1a54cfcb5588e2092de9f38 to your computer and use it in GitHub Desktop.
Save MrGrigri/907466afd1a54cfcb5588e2092de9f38 to your computer and use it in GitHub Desktop.
Used to animate the outline offset when an interactive element receives focus only when it's visible.
:root {
--outline-color: #346ebd;
--outline: 2px solid var(--outline-color);
}
* {
outline-offset: -2px;
}
*:not(:active):focus-visible {
outline: var(--outline);
outline-offset: 2px;
}
.focus-visible:has(:not(:active):focus-visible) {
outline: var(--outline);
outline-offset: 2px;
}
.focus-visible:has(:not(:active):focus-visible) :focus-visible {
outline: none;
}
@media (prefers-reduced-motion: no-preference) {
* {
will-change: outline-offset;
transition: outline-offset 75ms ease-out;
}
*:not(:active):focus-visible,
.focus-visible:has(:not(:active):focus-visible) {
transition: outline-offset 25ms ease-out;
}
}
@MrGrigri
Copy link
Author

MrGrigri commented Oct 6, 2022

Example Video

Screen.Recording.2022-10-06.at.12.35.12.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment