cheat/dev

Popover API + :popover-open

Janelas flutuantes nativas (menus, dicas, notificações) abertas por atributo HTML.

Sintaxe

<button popovertarget="menu">Abrir</button>
<div id="menu" popover>...</div>

O atributo popover faz o navegador cuidar de abrir/fechar, ESC, clique fora e camada superior (top layer), sem z-index. Estilize o estado aberto com :popover-open e o fundo com ::backdrop. Combine com @starting-style para animar.

Exemplo

<button popovertarget="info">Detalhes</button>
<div id="info" popover>Conteúdo do popover</div>

/* CSS */
[popover] { border: 1px solid #ddd; border-radius: 12px; padding: 16px; }
[popover]:popover-open { animation: surge .2s ease-out; }
[popover]::backdrop { background: rgb(0 0 0 / .3); }
@keyframes surge { from { opacity: 0; scale: .95; } }

Relacionados