Components
Anchor
A structural primitive to enable CSS Anchor Positioning on stuff.
Full supportSupported since v144.Full supportSupported since v151.Partial supportMissing:
popover-hint.Anatomy
Floating content
<Anchor>Container element. Scopes the anchor to its content.
v-slot:defaultThe content the floating content is anchored to.
v-slot:anchoredThe floating content.
Always Visible
Floating content that is always shown.
Floating content
<script setup lang="ts">import { Anchor } from "opui-css/vue"</script>
<template> <Anchor> <button>Hover me</button> <template #anchored ><span style=" background: var(--surface-2); padding: var(--size-2) var(--size-3); border-radius: var(--radius-2); box-shadow: var(--shadow-3); " >Floating content</span ></template > </Anchor></template><span class="ui-anchor" ><!--[--><button>Hover me</button><!--]--><span class="ui-anchor-floating" ><!--[--><span style=" background: var(--surface-2); padding: var(--size-2) var(--size-3); border-radius: var(--radius-2); box-shadow: var(--shadow-3); " >Floating content</span ><!--]--></span ></span>Hover Trigger
Set trigger="hover" and an id, and add interestfor with that id to the trigger. The component adds popover="hint".
Add interestfor, commandfor, and command="toggle-popover" to the anchor trigger so touch devices can tap to show the floating content.
Tooltip content
<script setup lang="ts">import { Anchor } from "opui-css/vue"</script>
<template> <Anchor trigger="hover" id="anchor-hover"> <button interestfor="anchor-hover" commandfor="anchor-hover" command="toggle-popover" > Hover me </button> <template #anchored ><div class="ui-card ui-elevated">Tooltip content</div></template > </Anchor></template><span class="ui-anchor" ><!--[--><button interestfor="anchor-hover" commandfor="anchor-hover" command="toggle-popover" > Hover me</button ><!--]--><span class="ui-anchor-floating" id="anchor-hover" popover="hint" ><!--[--> <div class="ui-card ui-elevated">Tooltip content</div> <!--]--></span ></span>Used By
API
Anchor API
| Prop | Type | Default | Description |
|---|---|---|---|
alignment | string | "start end" | Any valid position-area value. Controls where the floating content is placed. |
id | string | - | The id of the floating content when trigger is "hover". Add interestfor with the same id to the trigger. |
trigger | "always", "hover" | "always" | Shows the floating content always, or on hover and focus with popover="hint". |
Slots
| Slot | Description |
|---|---|
anchored | The floating content. |
default | The content the floating content is anchored to. |
Browser support
Full supportSupported since v144.Full supportSupported since v151.Partial supportMissing:
popover-hint.See also the full browser support guide.
Installation
@layer components.root { :where(.ui-anchor) { anchor-name: --anchor; anchor-scope: --anchor; display: inline-block; inline-size: fit-content;
/* Always-visible */ & > .ui-anchor-floating:not([popover]) { block-size: max-content; inline-size: max-content; position: absolute; position-anchor: --anchor; position-area: var(--anchor-position-area, start end); translate: var(--_anchor-tx, 0) var(--_anchor-ty, 0); }
/* Hover-triggered */ & > .ui-anchor-floating[popover] { inset: unset; margin: 0; position: absolute; position-area: var(--anchor-position-area, start end); translate: var(--_anchor-tx, 0) var(--_anchor-ty, 0); } }}