Skip to content

Instantly share code, notes, and snippets.

@Kcko
Last active November 7, 2025 08:55
Show Gist options
  • Select an option

  • Save Kcko/03d098a060dffcb226ccbdbd3eb69969 to your computer and use it in GitHub Desktop.

Select an option

Save Kcko/03d098a060dffcb226ccbdbd3eb69969 to your computer and use it in GitHub Desktop.
https://jsbin.com/hegesunoyu/3/edit?html,css,output
body {
min-height: 100vh;
min-height: 100dvh;
padding: 1em;
display: flex;
align-items: start; /* end for fallbacks ..*/
justify-content: start; /* end for fallbacks ..*/
font-family: Poppins, 'SegoeUI', Tahoma, Geneva, sans-serif;
}
button {
background: plum;
padding: 0.7em 1.5em;
border: none;
font-weight: 500;
border-radius: .3em;
anchor-name: --test;
}
#menu {
unset: all;
width: max-content;
border: 1px solid #ccc;
padding: 1rem;
background: #fff;
border-radius: .3em;
position: absolute;
margin: 0; /* important !!! */
position-anchor: --test;
top: anchor(bottom);
left: anchor(left);
position-try-fallbacks: --bottom-right, --bottom-left, --up-left, --up-right;
}
#menu:popover-open {
display: grid;
}
@position-try --bottom-right {
inset: unset;
top: anchor(bottom);
left: anchor(left);
}
@position-try --bottom-left {
inset: unset;
top: anchor(bottom);
right: anchor(right);
}
@position-try --up-left {
inset: unset;
bottom: anchor(top);
right: anchor(right);
}
@position-try --up-right {
inset: unset;
bottom: anchor(top);
left: anchor(left);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<button popovertarget="menu">Menu button</button>
<div id="menu" popover>
<a href="">Item 1</a>
<a href="">Another Item 2</a>
<a href="">Very long long long Item 3</a>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment