From ab30592d5edf6ce7945608ea5b3c2f23bd682496 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Fri, 6 Oct 2023 22:53:52 +0200 Subject: [PATCH] docs: add styling links example page (#1879) --- docs/canary/examples/active-links.md | 43 ++++++++++++++++++++++++++++ docs/toc.ts | 1 + 2 files changed, 44 insertions(+) create mode 100644 docs/canary/examples/active-links.md diff --git a/docs/canary/examples/active-links.md b/docs/canary/examples/active-links.md new file mode 100644 index 00000000..f05c8f91 --- /dev/null +++ b/docs/canary/examples/active-links.md @@ -0,0 +1,43 @@ +--- +description: | + Style active links with ease in Fresh +--- + +When Fresh renders an ``-element, it will automatically add a +[data attribute](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes) +to the link which can be used for styling purposes. Fresh will add one of the +two following attributes: + +- `data-current` - Added to links with an exact path match +- `data-ancestor` - Added to links which partially match the current URL + +## Styling with CSS + +`data-*` attributes can be natively styled in CSS via attribute selectors. + +```css +/* Give links pointing to the current page a green color */ +a[data-current] { + color: green; +} + +/* Color all ancestor links of the current page */ +a[data-ancestor] { + color: peachpuff; +} +``` + +## Tailwind / Twind + +In tailwind or tailwind like styling solutions you can style `data-*`-attributes +by prepending the classes with `[data-current]:` + +```tsx +function Menu() { + return ( + + link to some page + + ); +} +``` diff --git a/docs/toc.ts b/docs/toc.ts index 31eb2444..1357128a 100644 --- a/docs/toc.ts +++ b/docs/toc.ts @@ -96,6 +96,7 @@ const toc: RawTableOfContents = { ], ["using-deno-kv-oauth", "Using Deno KV OAuth", "link:latest"], ["using-csp", "Using CSP", "link:latest"], + ["active-links", "Styling active links", "link:canary"], ], }, },