AIGPAIGP

Responsive Cards! CSS Container Queries for Component-Level Layout

P

Prompt

Create a web page demonstrating CSS Container Queries with a card component that changes layout based on its container's width (inline-size). Use a grid of cards, each containing an image (placeholder), a title, and a description. The card should switch from horizontal (image left, text right) to vertical (image on top, text below) when the container is below 300px. Use container-type: inline-size and @container (max-width: 300px). Style with modern CSS (CSS custom properties, smooth transitions). Add a toggle button to shrink the parent container width to trigger the query. Include minimal JS for toggle and container resize.

CODE PREVIEW

エディタを読み込み中…

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

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

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

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

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

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

CSS Container Queries を使うと、ビューポートではなく親コンテナのサイズに応じて要素のスタイルを変更できます。再利用可能なコンポーネントを様々なレイアウトに適応させるのに最適です。このデモでは、コンテナ幅が300px未満になるとカードが横並びから縦並びに切り替わります。

container-type: inline-size@container (max-width: 300px) でレイアウトを制御。CSSカスタムプロパティとトランジションを組み合わせてスムーズな変化を実現。グローバルなメディアクエリに頼らないレスポンシブデザインに。

Prompt Overview

CSS Container Queries allow you to style elements based on their parent container's size, not the viewport. This is perfect for reusable components that need to adapt to various layouts. In this demo, cards switch from horizontal to vertical when the container width drops below 300px.

Use container-type: inline-size and @container (max-width: 300px) to control the layout. Combine with CSS custom properties and transitions for smooth results. Perfect for responsive design without global media queries.

Was this prompt helpful?

Comments

Comments appear after moderation

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

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

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

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

見る
Homeヘルプ