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】最大値や最小値を設定する方法

0
Posted at

min()

使い方

min()()内に記述された値のうち、最小の値を設定します。

width: min(100vw, 100px);

上記の場合には100vw100pxのうち小さい方の値が設定されます。

screen-recording-59.gif

max()

使い方

max()()内に記述された値のうち、最大の値を設定します。

width: max(100vw, 100px);

上記の場合には100vw100pxのうち大きい方の値が設定されます。

screen-recording-60.gif

clamp()

clamp() は CSS で値を 最小値推奨値最大値 の範囲内に収めるための関数です。

clamp() の基本構文

clamp(minimum, recommended, maximum)
  • minimum:最小値。これより小さくはならない。
  • recommended:推奨値。通常はこちらが適用される。
  • maximum:最大値。これより大きくはならない。

.card {
  width: clamp(200px, 50vw, 400px);
  padding: 1rem;
  background: #f5f5f5;
  border-radius: 8px;
}
  • ビューポート幅が狭いときは最低幅 200px
  • 推奨は画面幅の 50%
  • 広大な画面では最大幅 400px
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?