GifproGifpro

コンテナで変わる!CSS Container Queriesで作るレスポンシブカード

代码预览

エディタを読み込み中…
P

提示词

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.

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

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

这个提示对您有帮助吗?

评论

评论将在审核后显示

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

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

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

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

見る
首页ヘルプ