コンテナで変わる!CSS Container Queriesで作るレスポンシブカード
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.
VISTA DE CÓDIGO
エディタを読み込み中…
AIとの対話に追加する一言
プロンプトと一緒にコピーして、AIがより正確に意図を汲み取れるようにします
このコードをそのまま使いたいので、CDNリンクも含めた完全なHTMLファイルとして出力してください。
初心者なので、各行にコメントを追加して、何をしているか説明してください。
このコードをWordPressのテーマに組み込む方法も教えてください。
動作確認済みのコードをお願いします。エラーが出る場合の対処法も含めて。
CSS Container Queries を使うと、ビューポートではなく親コンテナのサイズに応じて要素のスタイルを変更できます。再利用可能なコンポーネントを様々なレイアウトに適応させるのに最適です。このデモでは、コンテナ幅が300px未満になるとカードが横並びから縦並びに切り替わります。
container-type: inline-size と @container (max-width: 300px) でレイアウトを制御。CSSカスタムプロパティとトランジションを組み合わせてスムーズな変化を実現。グローバルなメディアクエリに頼らないレスポンシブデザインに。
¿Te resultó útil este prompt?
Comentarios
Los comentarios aparecen después de la moderación
この記事が役に立ったら投げ銭で応援
Apple Pay / Google Pay / カード (Visa/Mastercard/JCB/Amex) / Link / Alipay / WeChat Pay 対応 · Stripeで安全に決済
開発者が選ぶ最強ツール集
運営者が毎日使っているツール・ガジェット 6選