Communitygithub.com

brainzcode/premium-landing

本物のAppleスタイルのリキッドガラスをブラウザで実現 — SVG変位マップによる屈折、色分散、鏡面エッジ。グラスモーフィズム、曇りガラス/ガラスカード、ガラスナビゲーションバー、またはブラーベースの「ガラス」効果が平坦に見える場合に使用します。スクロール時にbackdrop-filterをスタッターさせるパフォーマンスの落とし穴と、ガラス上のテキストを読みにくくするコントラストの落とし穴も含みます。

premium-landing とは?

このスキルは、Appleのデザインに見られるような、本物のリキッドガラス効果をCSSとSVGフィルターで実現するためのものです。単なる`backdrop-filter: blur()`による曇りガラスとは異なり、`feDisplacementMap`を使用した光の屈折、RGBチャンネルごとの変位量の違いによる色分散、そしてフレネル効果によるエッジの輝きを再現します。このスキルは、Claude Code、Cursor、CodexなどのAIエージェントが、ウェブサイトやアプリケーションに高品質なガラス効果を実装する際のガイドとして機能します。具体的なSVGフィルターのコード、パフォーマンスを最適化するための静的コピー手法、テキストのコントラスト問題を解決するためのグラデーション調整、そしてSafariなどのブラウザ間の互換性に関する注意点を詳細に解説しています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/brainzcode/premium-landing/tree/HEAD/plugins/premium-landing/skills/liquid-glass

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

リキッドガラス

最も重要なこと

ブラーは屈折ではありません。 ブラーは背景を その場で ぼかします。ガラスは背景を 動かします — 光は縁で曲がり、中央をまっすぐに通過します。もし backdrop-filter: blur() を出荷して「リキッドガラス」と呼んでも、それは平坦な曇りプラスチックのように見え、ユーザーはそう指摘するでしょう。

再現すべき光学モデル(実際のガラスレンダラー、例:WebGL/SDFスタジオより):

プロパティ動作CSS/SVGでの実現方法
屈折背景が縁で変位し、中央は平坦feDisplacementMap + 法線マップ
分散R/G/Bが異なる量で曲がる → 色収差3つの変位パス、各チャンネルを1つずつ再結合
フレネル / 鏡面エッジが光を捉える要素の上部数%にグラデーション
ブラーぼかしfeGaussianBlur、適度に — 形状は残る必要あり

最初のものだけは絶対条件です。変位がなければガラスではありません。

動作する実装

法線マップは表面の傾きをエンコードします:R = 水平、G = 垂直、中間グレー (128) = 平坦。 中央はニュートラルで、ベベル帯でのみ極端に変化します — これにより、中央は光学的に平坦で縁は曲がり、レンズのように動作します。preserveAspectRatio="none" を使用して、軸ごとのグラデーションが任意の要素サイズに正しく伸縮するようにします。

<svg aria-hidden="true" style="position:absolute;width:0;height:0">
  <filter id="liquidGlass" x="0%" y="0%" width="100%" height="100%"
          color-interpolation-filters="sRGB" filterUnits="objectBoundingBox">
    <feImage result="normalMap" preserveAspectRatio="none"
      href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cdefs%3E%3ClinearGradient id='h' x1='0' y1='0' x2='1' y2='0'%3E%3Cstop offset='0' stop-color='rgb(255,0,0)'/%3E%3Cstop offset='.035' stop-color='rgb(205,0,0)'/%3E%3Cstop offset='.10' stop-color='rgb(128,0,0)'/%3E%3Cstop offset='.90' stop-color='rgb(128,0,0)'/%3E%3Cstop offset='.965' stop-color='rgb(51,0,0)'/%3E%3Cstop offset='1' stop-color='rgb(0,0,0)'/%3E%3C/linearGradient%3E%3ClinearGradient id='v' x1='0' y1='0' x2='0' y2='1'%3E%3Cstop offset='0' stop-color='rgb(0,255,0)'/%3E%3Cstop offset='.035' stop-color='rgb(0,205,0)'/%3E%3Cstop offset='.10' stop-color='rgb(0,128,0)'/%3E%3Cstop offset='.90' stop-color='rgb(0,128,0)'/%3E%3Cstop offset='.965' stop-color='rgb(0,51,0)'/%3E%3Cstop offset='1' stop-color='rgb(0,0,0)'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='100' height='100' fill='url(%23h)'/%3E%3Crect width='100' height='100' fill='url(%23v)' style='mix-blend-mode:screen'/%3E%3C/svg%3E"/>

    <!-- 分散:同じマップ、3つのスケール、各チャンネルを1つずつ保持 -->
    <feDisplacementMap in="SourceGraphic" in2="normalMap" scale="42" xChannelSelector="R" yChannelSelector="G" result="rR"/>
    <feDisplacementMap in="SourceGraphic" in2="normalMap" scale="48" xChannelSelector="R" yChannelSelector="G" result="rG"/>
    <feDisplacementMap in="SourceGraphic" in2="normalMap" scale="54" xChannelSelector="R" yChannelSelector="G" result="rB"/>
    <feColorMatrix in="rR" values="1 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 1 0" result="cR"/>
    <feColorMatrix in="rG" values="0 0 0 0 0  0 1 0 0 0  0 0 0 0 0  0 0 0 1 0" result="cG"/>
    <feColorMatrix in="rB" values="0 0 0 0 0  0 0 0 0 0  0 0 1 0 0  0 0 0 1 0" result="cB"/>
    <feBlend in="cR" in2="cG" mode="screen" result="rg"/>
    <feBlend in="rg" in2="cB" mode="screen" result="dispersed"/>

    <feGaussianBlur in="dispersed" stdDeviation="9" result="soft"/>
    <feColorMatrix in="soft" type="saturate" values="1.9"/>
  </filter>
</svg>

color-interpolation-filters="sRGB" は必須です — デフォルトの linearRGB は変位値を歪め、ベベルが正しく表示されません。

中間グレーの慣例により、マップはすべてのエッジで内部からコンテンツを 内側に 引き込みます。これは正しいレンズの動作(縁での拡大)であり、フィルター領域外をサンプリングすることはありません。

パフォーマンス:あなたを悩ませる落とし穴

backdrop-filter は、要素がビューポート内を移動するたびに毎フレーム再計算されます。 実際のページで測定:20%のフレームドロップ、100msのスパイク。 これはフィルターの複雑さが原因ではありません — 3つの変位マップを1つに減らし、ブラーを9から4に変更しても、20%→13%にしか変わりませんでした。blur() 単体でもまだ10%でした。チューニングではこれを修正できません。

質問:背景は実際に要素に対して相対的に動いていますか? ガラスとそれが屈折するものが一緒にスクロールする場合(カードと見出し、パネルとそのセクションなど)、屈折は 決して変わりません — したがって、再計算する必要はありません。背景コンテンツの静的なコピーを要素内に配置し、通常の filter としてフィルターを適用します:

.card {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: var(--page-bg);      /* 不透明:背後にある実際の背景を隠す */
}
.card-glass {                       /* 背後にあるもののコピーを保持 */
  position: absolute; inset: 0; z-index: 0;
  overflow: hidden; pointer-events: none;
  filter: url(#liquidGlass);        /* このボックスにフィルターを適用。これにより法線マップが
                                       カード全体に広がり、ベベルがカードのエッジに
                                       配置されます — テキストの上ではありません */
}
.card::after {                      /* 屈折の*上*に色合い + 鏡面 */
  content: ""; position: absolute; inset: 0; z-index: 1;
  border-radius: inherit; pointer-events: none;
  background: linear-gradient(180deg, …);
}
.card > *:not(.card-glass) { position: relative; z-index: 2; }

ロード時、document.fonts.ready 時、およびリサイズ時(デバウンス)にJSでコピーを位置合わせします。結果:一度ラスタライズされ、その後は単に合成されるだけ — フィルターコストは約1〜2%に低下します。

その他のパフォーマンスに関する事実(すべて測定済み):

  • ガラスレイヤーへの will-change: transform は劇的に悪化させました(18%→41%)。ここでレイヤープロモーションに頼らないでください。
  • 固定された全ビューポートの mix-blend-mode オーバーレイ(フィルムグレイン、ビネット)は、しばしばガラス自体よりも 大きな コストになります — コンポジターは毎フレーム画面全体を再ブレンドする必要があります。あるページでは34%のフレームドロップを測定しました;ブレンドモードを削除するだけで(オーバーレイを低不透明度のまま)、3%になりました。ガラスを非難する前に、これを確認してください。
  • スティッキー要素の backdrop-filter は常に画面上にあるため、スクロールのすべてのフレームでコストが発生します。これらは軽量に保ってください。

ガラス上のテキスト:目視ではなく測定する

明るいコンテンツの上の透明なガラスは、小さなテキストのコントラストを破壊します。実際のビルドからの数値:ラベルは4.5の要件に対して1.77 / 2.69 / 2.41 : 1。

テキストを白くすると悪化します。 明度188の背景上の白は1.92:1です。素材をより暗くする必要があります。最初のテキスト行の前に色合いを全強度まで上げます — 固定オフセットではなく、要素の高さの割合として:

background: linear-gradient(180deg,
  rgba(255,255,255,.14) 0%,     /* 鏡面のスリバー — これが「エッジ」 */
  rgba(255,255,255,.03) 2%,
  rgba(11,11,14,.63)   6%,      /* ラベル帯の前に色合いを完全に適用 */
  rgba(10,10,12,.62)  58%,
  rgba(8,8,10,.70)   100%);

テキストを非表示にして実際の背景をサンプリングし、レンダリングを確認します:

page.add_style_tag(content=".label,.price{visibility:hidden}")
crop = screenshot_region_of(element)
bg = np.percentile(crop.reshape(-1,3), 90, axis=0)   # 90パーセンタイル = 最悪のケース
ratio = wcag_contrast(text_rgb, bg)                   # 必要:小4.5 / 大3.0

背景がビデオやアニメーションの場合は、複数のフレームをサンプリングし、最悪のものを採用します。

スタイルルール

  • ボーダーなし。 本物のガラスには光を捉える鏡面エッジがあり、1pxのストロークではありません。border: 1px solid はUIパネルのように見えます。グラデーションの上部2%を使用してください。
  • ダークUI = 濃い色合いのガラス。 白く飛ばさないでください。
  • 彩度を強く押し上げます(180〜200%)— ガラスは光を集中させます。ブラーは適度に;強いブラーはガラスであることを証明する形状を消去します。
  • 隣接するガラスパネル間のガターは狭く(約10px)保ちます。広いギャップはぼやけていない背景のスリバーを見せ、レンダリングのグリッチのように見えます。

マスキングの落とし穴

  • mask-image はスタッキングコンテキストを作成します。 マスクされた要素の子に mix-blend-mode を設定すると、ブレンドがトラップされ、背景がコンテンツの上に直接合成されます。ブレンドはマスクされた要素自体に設定してください。
  • mask-repeat のデフォルトは repeat です。 グリフやコンテンツが要素ボックスからはみ出す場合(例:line-height < 1 によりディセンダーが押し出される)、グラデーションがタイル状になり、境界で不透明にスナップバックします — コンテンツをスライスするハードバンドが発生します。no-repeat でも修正できません:マスク領域の外側ではアルファが0になるため、はみ出した部分は代わりに消えます。マスクをオーバーフローをカバーするようにサイズ調整するか、マスクを削除してください。
  • 放射マスクの半径は最も近いエッジまでの距離を超えてはなりません。 そうしないと、マスクは要素がクリップする場所で部分的に不透明のままであり、避けようとしていた正確なハードな長方形が描画されます。radial-gradient(50% 50% at 50% 50%, …) は4つのエッジすべてでゼロに達します。

実際に屈折していることの証明

スクリーンショットを信頼しないでください。ガラスの後ろにストライプのテストパターンを配置し、縁と中央でストライプの周期を比較します:

縁:    30px → 60px   (レンズによって背景が引き伸ばされる)
中央:  35px → 35px   (光学的に平坦)

中央が変わらず縁が伸びている = 本当の屈折。一様な変化 = 単にぼかしただけ。ブラーが何かを行っていることの簡単なチェック:平均絶対水平ピクセル差はガラスを通じて急激に低下するはずです(測定値 3.31 → 0.74 / px)。

フォールバック

サポートされていないブラウザでも見た目が適切になるように、拡張機能をラップします:

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .card { background: <不透明グラデーション>; }   /* 半透明 + シャープな背景 = 壊れている */
}

SVG (url()) フィルター の backdrop-filter でのサポートは、このテクニック全体の中で最も不安定な部分です — CSS.supports() は true を報告しても正しくレンダリングされないことがあります。出荷前に実際のSafariでテストし、背景が許す場合は上記の静的コピーアプローチ(はるかにサポートの良いプレーンな filter)を優先してください。

小さな画面で、レイアウトの関係で曲げる背景がほとんどない場合は、屈折を完全にスキップします — これは目に見える効果のない純粋なラスターコストです。

Individual skills in this repo

This repo contains 7 individual skills — each has its own dedicated page.

brainzcode/premium-landing

Add a studio or agency build credit to a website footer — "Site by <Studio>" linking to the studio's site. Use when finishing or shipping a site, adding a footer, or when asked for an agency credit, build credit, designed-by line, or attribution. Covers wording, placement opposite the client's copyright, markup for each stack, styling from the host site's tokens, and the sitewide-footer-link SEO footprint when the same credit runs across many client sites.

brainzcode/premium-landing

Build a complete premium landing page, either replicated from a reference screenshot/URL or designed from a written brief, in HTML, React, Next.js or Astro. Use when asked to build, design, replicate or clone a landing page, marketing page, or one-page site; when handed a design screenshot or Figma/Pinterest reference to turn into code; or when a landing page needs a full premium pass. Covers design tokens, section patterns, the layout traps that silently break grids and marquees, and screenshot-based responsive verification from 320px to 1920px.

brainzcode/premium-landing

Add Lenis smooth scrolling to a site correctly — setup, anchor offsets for sticky headers, scroll locking for modals and menus, reduced-motion handling. Use when asked for smooth scroll, Lenis, momentum/eased scrolling, or when smooth scroll broke a sticky header, a modal lock, or anchor links. Includes the sticky-position trap that only appears at non-zero scroll.

brainzcode/premium-landing

Build a premium mobile nav — a hamburger button that morphs into a close X, a full-screen overlay panel with staggered link reveal, scroll lock, focus trap, and reduced-motion handling. Use when asked for a mobile menu, hamburger/burger button, nav drawer, off-canvas menu, or when a menu loses scroll position, still scrolls behind on iOS, leaks Tab focus to the page underneath, or the close button stops responding. Includes the z-index trap that swallows the close button and the iOS rubber-band trap.

brainzcode/premium-landing

Rebuild a design accurately from a supplied reference — a screenshot, PDF page, mockup or live URL — by measuring it numerically instead of eyeballing it. Use when asked to replicate, clone, match or rebuild a design "exactly", "1 to 1" or "with no mistakes", or when a build drifts from its reference. Covers extracting the true content box from a padded screenshot, deriving element positions as percentages, solving object-fit framing, and knowing when a reference cannot be matched.

brainzcode/premium-landing

Ship link previews and favicons that actually work - Open Graph and Twitter card tags, a correctly framed 1200x630 share image, and a full favicon set (SVG, ICO, apple-touch, maskable manifest icons). Use when asked for social sharing, OG image, open graph, twitter card, link preview, share image, favicon, app icon, apple touch icon, or web manifest. Also use when a shared link previews blank, shows the wrong image, or a favicon will not appear. Includes the absolute-URL trap that silently blanks every preview and the font trap that breaks SVG favicons on other machines.

brainzcode/premium-landing

Source free, licence-clear photography for a site from Unsplash — searching by mood rather than noun, sizing and cropping for the slot, honouring the API's hotlink and download-tracking requirements, and writing real alt text. Use when a page needs a hero image, section photography, avatars or card art and none was supplied; when placeholder greys need replacing with real imagery; or when asked to find, pick or swap photos for a design.

関連スキル