AIGPAIGP

Anchor Away! CSS Anchor Positioning for Floating UI

P

Prompt

Create a demo of CSS anchor positioning: a tooltip that follows an anchor element. Use a button as anchor, and a div positioned with anchor() and position-area/position-try. The tooltip should adjust if close to edges.

CODE PREVIEW

エディタを読み込み中…

AIとの対話に追加する一言

プロンプトと一緒にコピーして、AIがより正確に意図を汲み取れるようにします

このコードをそのまま使いたいので、CDNリンクも含めた完全なHTMLファイルとして出力してください。

初心者なので、各行にコメントを追加して、何をしているか説明してください。

このコードをWordPressのテーマに組み込む方法も教えてください。

動作確認済みのコードをお願いします。エラーが出る場合の対処法も含めて。

CSS Anchor Positioningを使うと、要素を別の要素(アンカー)に固定できます。position-anchorでアンカーを指定し、position-areaで配置位置を決めます。position-try-optionsプロパティで、ビューポートからはみ出す場合の代替位置を定義可能。このデモではツールチップがボタンに寄り添い、スペース不足で反対側に反転します。

Prompt Overview

CSS Anchor Positioning lets you attach an element to another element (anchor) using position-anchor and position-area. The position-try-options property defines fallback positions when the element would overflow the viewport. In this demo, the tooltip stays next to its anchor button and flips to the opposite side if space runs out.

Was this prompt helpful?

Comments

Comments appear after moderation

この記事が役に立ったら投げ銭で応援

Apple Pay / Google Pay / カード (Visa/Mastercard/JCB/Amex) / Link / Alipay / WeChat Pay 対応 · Stripeで安全に決済

開発者が選ぶ最強ツール集

運営者が毎日使っているツール・ガジェット 6選

見る
Homeヘルプ