1
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?

More than 3 years have passed since last update.

CSS Grid Layout の minmax() は auto-fill かどうかで文法が異なる

Last updated at Posted at 2022-03-01

タイトルの通りなのですが、たびたび忘れてしまうのでメモ代わりに。
なお、日本語版のMDNの記述は微妙に間違っている。英語版は正しい記述だが、下記のことは説明されていない、と思います。

grid-template, grid-auto-columns, grid-auto-rows などで使う場合

repeat(i, ...)で使う場合もこちら。

grid-template: minmax( 
                 [ 100px | 100% | min-content | max-content | auto ],
                 [ 100px | 100% | 1fr | min-content | max-content | auto ]
);

fr単位を使えるのは、max側だけ。


repeat(auto-fill, ...) の中で使う場合

auto-fitも同様。

grid-template: repeat(auto-fill, minmax( 
                 [ 100px | 100% ],
                 [ 100px | 100% | 1fr | min-content | max-content | auto ]
));

または、

grid-template: repeat(auto-fill, minmax( 
                 [ 100px | 100% | min-content | max-content | auto ],
                 [ 100px | 100% ]
));

のどちらか。

つまるところ、

  • fr単位を使いたいなら、min側はコンテンツ依存にできない。
  • 片方をコンテンツ依存にしたいなら、もう一方は長さを固定しなくてはいけない。

ということかと思います。


仕様へのリンク

7.2.3.1. Syntax of repeat() | CSS Grid Layout Module Level 2

1
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
1
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?