2
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】overflowのhiddenとclipの違い

2
Posted at

overflow: hidden

  • はみ出したコンテンツを視覚的に隠す
  • プログラムによるスクロールが可能
  • 要素は依然として「スクロールコンテナ」として機能

overflow: clip

  • はみ出したコンテンツを視覚的に隠す
  • プログラムによるスクロールを完全に無効化
  • 要素はスクロールコンテナではなくなる

プログラム的スクロールの動作例

// overflow: hiddenの場合
const hiddenElement = document.getElementById("hidden");
hiddenElement.scrollTop = hiddenElement.scrollHeight; // 動作する

// overflow: clipの場合
const clipElement = document.getElementById("clip");
clipElement.scrollTop = clipElement.scrollHeight; // 動作しない

軸ごとの制御における違い

overflow: hiddenでは、軸ごとに異なる値を設定する際に制限があります。

/* 問題:x軸のvisibleが無効になる */
.element {
  overflow-x: visible;
  overflow-y: hidden;
}

一方、overflow: clipでは軸間の依存関係がありません。

/* 正常動作:x軸は表示、y軸はクリップ */
.element {
  overflow-x: visible;
  overflow-y: clip;
}
2
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
2
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?