0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【CSS】Gridが苦手なすべての人へ。これだけ覚えればOKな「最小限」のレイアウト術

0
Posted at

こんにちは!CSSの Grid レイアウト、便利そうだけどプロパティが多くて複雑…。なんだか苦手意識を持っていませんか?

grid-template-columns や fr 単位、grid-area など、全部を覚えようとすると頭がパンクしちゃいますよね。

今回は、**「Gridが苦手なら、まずはこの3つ(実質2つ)だけ覚えればOK!」**という、挫折しないための最小限ハックをご紹介します。


1. そもそも Grid って何?(Flexboxとの違い)

  • Flexbox:1方向(横並び、または縦並び)が得意
  • Grid:2方向(縦と横の両方)を同時に管理して、マス目(格子状)に配置するのが得意

「カードをきれいに並べたい」「2カラムのレイアウトを作りたい」ときは、Gridを使うと驚くほどコードがスッキリします。


2. これだけ覚えればOK!必須の呪文はたったのこれだけ

Gridを使うときの親要素(コンテナ)に、以下のセットを書くだけでレイアウトが完成します。

.container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?