<button popovertarget="my-tooltip">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z" />
</svg>
<span class="sr-only">Toggle tooltip</span>
</button>
<!-- for demo reasons, the popover is set to manual :) feel free to change it to auto if you want to light dismiss it -->
<div id="my-tooltip" popover="manual">Look at the cute little popover</div>
<fieldset class="controls">
<legend>Position icon:</legend>
<div class="grid">
<label><input type="radio" name="position" class="top left" /><span class="sr-only">top left</span></label>
<label><input type="radio" name="position" class="top center" /><span class="sr-only">top center</span></label>
<label><input type="radio" name="position" class="top right" /><span class="sr-only">top righ</span></label>
<label><input type="radio" name="position" class="left" /><span class="sr-only">left</span></label>
<label><input type="radio" name="position" class="center" checked /><span class="sr-only">center</span></label>
<label><input type="radio" name="position" class="right" /><span class="sr-only">right</span></label>
<label><input type="radio" name="position" class="bottom left" /><span class="sr-only">bottom left</span></label>
<label><input type="radio" name="position" class="bottom center" /><span class="sr-only">bottom center</span></label>
<label><input type="radio" name="position" class="bottom right" /><span class="sr-only">bottom right</span></label>
</div>
</fieldset>
/* For this anchoring to work, reset the margin of the popover and display the anchor (button in this case) as a grid */
[popover] {
inset: unset;
background: hotpink;
color: white;
border-radius: 0.5rem;
border: 0;
padding: 1rem;
margin: 0.5rem;
/* position */
position-anchor: --button;
position-area: top right;
position-try-fallbacks: flip-inline, flip-block, flip-block flip-inline;
position-try-order: most-width;
}
button {
all: unset;
anchor-name: --button;
transition: color 0.4s ease-out;
&:is(:hover, :focus) {
color: hotpink;
}
}
svg {
width: 3rem;
aspect-ratio: 1;
}
body {
display: flex;
flex-direction: column;
align-items: var(--align, center);
justify-content: var(--justify, center);
min-height: 100dvh;
margin: 0;
font-family: sans-serif;
font-size: 1.16rem;
line-height: 1.6;
color: #fff;
background: #2b2c28;
}
@layer controls {
.controls {
position: fixed;
bottom: 20vh;
margin: 0;
left: 50%;
transform: translateX(-50%);
padding: 0.25rem;
}
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: center;
}
label,
input {
width: 1.5rem;
aspect-ratio: 1;
margin: 0;
padding: 0;
}
input[type="radio"] {
accent-color: deeppink;
cursor: pointer;
}
body:has(.left:checked) {
--align: start;
}
body:has(.right:checked) {
--align: end;
}
body:has(.center:checked) {
--justify: center;
}
body:has(.top:checked) {
--justify: start;
}
body:has(.bottom:checked) {
--justify: end;
}
.sr-only {
clip: rect(1px, 1px, 1px, 1px);
clip-path: inset(50%);
height: 1px;
width: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
}
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.