Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Understanding Grid Containers and Items | Getting Started with CSS Grid
CSS Grid Mastery

bookUnderstanding Grid Containers and Items

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

Grid Containers and Grid Items: The Foundation of CSS Grid

CSS Grid revolutionizes web layout by introducing a powerful system for creating two-dimensional designs. At its core, CSS Grid relies on two essential concepts: the grid container and grid items.

  • A grid container is any element to which you apply grid-related CSS properties, transforming it into the parent context for a grid layout;
  • The immediate children of this container automatically become grid items, each participating in the grid structure.

This foundational relationship allows you to organize content into rows and columns with precise control, making complex layouts straightforward to implement.

index.html

index.html

styles.css

styles.css

copy

The Role of display: grid in CSS Grid

The key property that activates grid layout is display: grid. When you assign display: grid to an element, it becomes a grid container, establishing a new grid formatting context. This means that the browser will treat its direct children as grid items, organizing them according to the grid rules you define.

  • Only the immediate children of the grid container participate as grid items;
  • Nested elements deeper in the DOM do not become grid items unless their parent is also a grid container.

This clear separation of container and items is the foundation for building flexible, responsive layouts using CSS Grid.

question mark

Which statement best describes the relationship between a grid container and grid items in CSS Grid?

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

すべて明確でしたか?

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

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

セクション 1.  1

AIに質問する

expand

AIに質問する

ChatGPT

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

セクション 1.  1
some-alt