Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Media Queries with Grid | Responsive and Production-Ready Grid Layouts
CSS Grid Mastery

bookMedia Queries with Grid

メニューを表示するにはスワイプしてください

How Media Queries Work with Grid

To create layouts that work seamlessly on any device, you need to combine CSS Grid with media queries. Media queries allow you to apply different grid properties depending on the screen size, orientation, or device features. By changing grid templates, gaps, or even item placement at specific breakpoints, you can ensure your design remains functional and visually appealing across desktops, tablets, and smartphones. Grid properties such as grid-template-columns, grid-template-rows, and grid-area can all be redefined inside media queries, letting you reorganize content without rewriting your HTML.

index.html

index.html

styles.css

styles.css

copy

Mobile-First vs. Desktop-First Grid Strategies

When building responsive grid layouts, you can use either a mobile-first or desktop-first approach:

Mobile-First

  • Define your grid for the smallest screens first;
  • Add more complex grid rules for larger devices using min-width media queries;
  • This method generally leads to better performance and simpler overrides.

Desktop-First -Start with a layout suited for large screens;

  • Use max-width queries to simplify the grid for smaller devices;
  • This approach can be useful when your primary audience uses desktops.

Whichever strategy you choose, ensure your breakpoints are based on your content and design needs, not just device sizes.

question mark

Which of the following media queries would you use to change a grid layout for screens wider than 900px?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 4.  1

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 4.  1
some-alt