【CSS】insetの使い方:配置の一括指定・内側の影・スマホセーフエリア対応

css-inset

CSSのinsetは、要素の配置を1行で済ませるだけでなく、影や画像の切り抜き、スマホのセーフエリア対応にまで登場するモダンWeb制作の必須キーワードです。

本記事では、一括指定の基本から絶対配置での中央寄せ、内側シャドウの作り方、ノッチ回避対応まで実務で迷わないinsetの活用法を解説します。

また、CSSに関するカテゴリーページから学びたい内容を決めたい人は、以下のCSSページをご確認ください。

目次

insetプロパティとは:配置(上下左右)の一括指定

Web制作において、要素を絶対配置(position: absolute;)や固定配置(position: fixed;)にする際、これまでtop,right,bottom,leftの4つのプロパティを書き連ねてきました。

しかし、現代のCSSではinsetという画期的なプロパティがあります。

insetを一言で表すと、上下左右の配置位置を1行で一括指定できるショートハンド(省略記法)です。

ここでは、基本的なショートハンドの法則、実務で頻出する全画面オーバーレイ、論理プロパティへの応用を解説します。

insetプロパティとは:配置(上下左右)の一括指定
  • toprightbottomleftを1行で書くショートハンド
  • inset: 0;を使った全画面配置と上下左右の中央寄せ
  • marginとの違いと論理プロパティ

top・right・bottom・leftを1行で書くショートハンド

insetプロパティの書き方は、おなじみのmarginpaddingのショートハンドと同じ「時計回りの法則」です。

値を4つ書けば「上・右・下・左」、2つ書けば「上下・左右」、1つ書けば「上下左右すべて」に適用されます。

insetを書くなら、直前にpositionをセットで書く」というルールを覚えておきましょう。

実務では、position: absolute;inset: 10px 20px;の組み合わせで、親要素(position: relative;を指定したコンテナ)からの距離を1行で制御するのがよいです。

⭕️ 4行必要だった配置指定が、insetならたった1行で完結する!

旧来の書き方(4行)

OLD

insetを使った書き方(1行)

NEW
/* 💡 共通:親要素には必ず relative を指定する */
.parent {
  position: relative;
}

/* ❌ 古いコード:4行も書いていて長ったらしい */
.child-old {
  position: absolute;
  top: 10px;
  right: 20px;
  bottom: 30px;
  left: 40px;
}

/* ⭕️ insetを使って1行でスマートに書く(時計回り) */
.child-modern {
  position: absolute; /* 💡 これを忘れると inset は効かない! */
  inset: 10px 20px 30px 40px; /* 💡 上・右・下・左の順 */
}
HTMLコード表示
<div class="inset-layout-wrapper">
  <p class="inset-caption">⭕️ 4行必要だった配置指定が、insetならたった1行で完結する!</p>

  <div class="inset-demo-area">
    
    <div class="inset-box-wrapper">
      <p class="inset-label">旧来の書き方(4行)</p>
      <div class="inset-parent">
        <div class="inset-child-old">OLD</div>
      </div>
    </div>

    <div class="inset-box-wrapper">
      <p class="inset-label inset-text-blue">insetを使った書き方(1行)</p>
      <div class="inset-parent">
        <div class="inset-child-modern">NEW</div>
      </div>
    </div>

  </div>

  <div class="inset-code-area">
    /* 💡 共通:親要素には必ず relative を指定する */<br>
    <span class="hl-blue">.parent</span> {<br>
      <span class="hl-green">position: relative;</span><br>
    }<br><br>

    /* ❌ 古いコード:4行も書いていて長ったらしい */<br>
    <span class="hl-blue">.child-old</span> {<br>
      <span class="hl-green">position: absolute;</span><br>
      <span class="hl-red">top: 10px;</span><br>
      <span class="hl-red">right: 20px;</span><br>
      <span class="hl-red">bottom: 30px;</span><br>
      <span class="hl-red">left: 40px;</span><br>
    }<br><br>

    /* ⭕️ insetを使って1行でスマートに書く(時計回り) */<br>
    <span class="hl-blue">.child-modern</span> {<br>
      <span class="hl-green">position: absolute;</span> /* 💡 これを忘れると inset は効かない! */<br>
      <span class="hl-red">inset: 10px 20px 30px 40px;</span> /* 💡 上・右・下・左の順 */<br>
    }
  </div>
</div>
CSSコード表示
.inset-layout-wrapper {
  background-color: #f8f9fa;
  padding: 30px;
  border-radius: 8px;
  border: 1px solid #dee2e6;
}

.inset-caption {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 30px;
  color: #198754;
  text-align: center;
}

.inset-demo-area {
  display: flex;
  justify-content: center;
  gap: 40px;
  background-color: #e9ecef;
  padding: 40px;
  border-radius: 8px;
  border: 1px dashed #adb5bd;
  margin-bottom: 20px;
}

.inset-box-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1;
  max-width: 250px;
}

.inset-label {
  font-size: 13px;
  font-weight: bold;
  color: #333;
  margin-bottom: 15px;
  text-align: center;
}

.inset-text-blue {
  color: #0d6efd;
}

/* =親コンテナ= */
.inset-parent {
  position: relative; /* 💡 子要素の絶対配置の基準となる */
  width: 100%;
  height: 150px;
  background-color: #fff;
  border: 2px solid #ced4da;
  border-radius: 4px;
}

/* =❌ 旧来の書き方= */
.inset-child-old {
  position: absolute;
  top: 10px;
  right: 20px;
  bottom: 30px;
  left: 40px;
  background-color: #6c757d;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  border-radius: 4px;
}

/* =⭕️ モダンな書き方= */
.inset-child-modern {
  position: absolute;
  inset: 10px 20px 30px 40px; /* 💡 1行で完結 */
  background-color: #0d6efd;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  border-radius: 4px;
}

.inset-code-area {
  background-color: #282c34;
  color: #abb2bf;
  padding: 20px;
  border-radius: 6px;
  font-family: monospace;
  font-size: 13px;
  line-height: 1.6;
  border-left: 4px solid #0d6efd;
}

.hl-blue { color: #61afef; font-weight: bold; }
.hl-red { color: #e06c75; font-weight: bold; }
.hl-green { color: #98c379; font-weight: bold; }

paddingmarginpositionの使い方を詳しく知りたい人は以下から一読ください。

inset: 0;を使った全画面配置と上下左右の中央寄せ

実務においてinsetが活躍する瞬間が「全画面を覆う半透明の背景(オーバーレイ)」や「モーダルウィンドウの中央寄せ」を作るときです。

これまでtop: 0; right: 0; bottom: 0; left: 0;と長々書いていた全画面指定は、inset: 0;のたった8文字で完了します。

また、この性質を利用した中央寄せのテクニックは、FlexboxやGridが登場する前から使われていて、現在でもモーダル実装などで使用されます。

絶対配置で上下左右の中央に配置する際は、『position: absolute;,inset: 0;,margin: auto;,widthheight(固定値)』の4点セットを記述することです。

固定サイズを持たせた上で、四方からinset: 0で引っ張り、margin: auto;で余白を均等に分配することでブラウザが中央に要素を配置します。

⭕️ inset: 0; の魔法。サムネイルの「暗いカバー」も「中央の再生ボタン」も一瞬で作れる

Sample Video
/* ⭕️ 背景を暗くする「全画面カバー」を1行で作る */
.video-overlay {
  position: absolute;
  inset: 0; /* 💡 上下左右0に引っ張り、親のサムネイル全体を覆う! */
  background-color: rgba(0, 0, 0, 0.4);
}

/* ⭕️ 再生ボタンを「完全など真ん中」に配置する4点セット */
.play-button {
  position: absolute;
  inset: 0; /* 💡 1. 四方に引っ張る */
  margin: auto; /* 💡 2. 引っ張った余白を上下左右で均等に割り振る(=中央になる) */
  width: 60px; /* 💡 3. 幅を固定する */
  height: 60px; /* 💡 4. 高さを固定する */
}
HTMLコード表示
<div class="inset-layout-wrapper">
  <p class="inset-caption">⭕️ inset: 0; の魔法。サムネイルの「暗いカバー」も「中央の再生ボタン」も一瞬で作れる</p>

  <div class="inset-demo-area">
    
    <div class="inset-video-card">
      
      <div class="inset-video-overlay"></div>
      
      <div class="inset-play-button">
        ▶
      </div>

      <div class="inset-video-title">Sample Video</div>
    </div>

  </div>

  <div class="inset-code-area">
    /* ⭕️ 背景を暗くする「全画面カバー」を1行で作る */<br>
    <span class="hl-blue">.video-overlay</span> {<br>
      <span class="hl-green">position: absolute;</span><br>
      <span class="hl-red">inset: 0;</span> /* 💡 上下左右0に引っ張り、親のサムネイル全体を覆う! */<br>
      <span class="hl-green">background-color: rgba(0, 0, 0, 0.4);</span><br>
    }<br><br>

    /* ⭕️ 再生ボタンを「完全など真ん中」に配置する4点セット */<br>
    <span class="hl-blue">.play-button</span> {<br>
      <span class="hl-green">position: absolute;</span><br>
      <span class="hl-red">inset: 0;</span> /* 💡 1. 四方に引っ張る */<br>
      <span class="hl-red">margin: auto;</span> /* 💡 2. 引っ張った余白を上下左右で均等に割り振る(=中央になる) */<br>
      <span class="hl-red">width: 60px;</span> /* 💡 3. 幅を固定する */<br>
      <span class="hl-red">height: 60px;</span> /* 💡 4. 高さを固定する */<br>
    }
  </div>
</div>
CSSコード表示
.inset-layout-wrapper {
  background-color: #f8f9fa;
  padding: 30px;
  border-radius: 8px;
  border: 1px solid #dee2e6;
}

.inset-caption {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 30px;
  color: #198754;
  text-align: center;
}

.inset-demo-area {
  display: flex;
  justify-content: center;
  background-color: #e9ecef;
  padding: 40px;
  border-radius: 8px;
  border: 1px dashed #adb5bd;
  margin-bottom: 20px;
}

.inset-video-card {
  position: relative !important; /* 💡 配置の基準点 */
  width: 100%;
  max-width: 360px;
  height: 200px;
  /* サムネイル画像の代わりのグラデーション */
  background: linear-gradient(135deg, #0d6efd, #0dcaf0);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 15px rgba(0,0,0,0.1);
  margin: 0 auto;
}

/* =💡 実践コード1:暗いオーバーレイ= */
.inset-video-overlay {
  position: absolute !important;
  inset: 0 !important; /* 💡 たったこれだけで全画面を覆う */
  background-color: rgba(0, 0, 0, 0.4) !important;
  margin: 0 !important;
  padding: 0 !important;
  z-index: 1;
}

/* =💡 実践コード2:再生ボタンの中央寄せ= */
.inset-play-button {
  position: absolute !important;
  inset: 0 !important; /* 💡 四方に引っ張る */
  margin: auto !important; /* 💡 余白を均等に分配する(WPテーマの余白を強制上書き) */
  width: 64px !important; /* 💡 サイズ指定 */
  height: 64px !important; /* 💡 サイズ指定 */
  
  /* 再生ボタンの見た目装飾 */
  background-color: rgba(255, 255, 255, 0.9);
  color: #0d6efd;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  padding-left: 6px !important; /* 三角形を視覚的に中央に見せる微調整 */
  box-sizing: border-box;
  z-index: 10;
  cursor: pointer;
  transition: transform 0.2s;
}

.inset-play-button:hover {
  transform: scale(1.1);
  background-color: #fff;
}

/* おまけ:左下のタイトル */
.inset-video-title {
  position: absolute;
  bottom: 15px;
  left: 15px;
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  z-index: 2;
  letter-spacing: 1px;
}

.inset-code-area {
  background-color: #282c34;
  color: #abb2bf;
  padding: 20px;
  border-radius: 6px;
  font-family: monospace;
  font-size: 13px;
  line-height: 1.6;
  border-left: 4px solid #0d6efd;
}

.hl-blue { color: #61afef; font-weight: bold; }
.hl-red { color: #e06c75; font-weight: bold; }
.hl-green { color: #98c379; font-weight: bold; }

marginとの違いと論理プロパティ

初学者が混乱しやすいのが「要素の位置をずらす」という目的において、insetmarginのどちらを使うべきかという点です。

現代のCSSでは、多言語対応(RTLや縦書き)を前提とした「論理プロパティ」の概念が導入され、inset-blockinset-inlineといった新しい記述方法が標準になりつつあります。

グローバルなWeb開発(多言語対応)における流れとして、「上下」や「左右」といった物理的な方向の指定はレガシー(古い)とされつつあります。

代わりに、「ブロック軸」を制御するinset-blockと「インライン軸」を制御するinset-inlineを使用します。

これにより、アラビア語(右から左)や日本語の縦書きに切り替えた際も、CSSを書き直すことなくレイアウトが破綻しないコンポーネントが構築できます。

⭕️ top/left の時代は終わり。多言語に強い inset-block / inset-inline を使おう

論理プロパティの
バッジ
/* ❌ 旧来の物理プロパティ(アラビア語等でレイアウトが崩れる) */
.badge-old {
  position: absolute;
  top: 10px; /* 物理的な「上」 */
  left: 10px; /* 物理的な「左」 */
}

/* ⭕️ モダンな論理プロパティで指定する */
.badge-modern {
  position: absolute;
  /* 💡 block-start = 通常は「上」。縦書きなら「右」になる */
  inset-block-start: 15px;

  /* 💡 inline-start = 通常は「左」。アラビア語なら「右」になる */
  inset-inline-start: 15px;
}
HTMLコード表示
<div class="inset-layout-wrapper">
  <p class="inset-caption">⭕️ top/left の時代は終わり。多言語に強い inset-block / inset-inline を使おう</p>

  <div class="inset-demo-area">
    
    <div class="inset-logical-container">
      <div class="inset-logical-item">
        論理プロパティの<br>バッジ
      </div>
    </div>

  </div>

  <div class="inset-code-area">
    /* ❌ 旧来の物理プロパティ(アラビア語等でレイアウトが崩れる) */<br>
    <span class="hl-blue">.badge-old</span> {<br>
      <span class="hl-green">position: absolute;</span><br>
      <span class="hl-red">top: 10px;</span> /* 物理的な「上」 */<br>
      <span class="hl-red">left: 10px;</span> /* 物理的な「左」 */<br>
    }<br><br>

    /* ⭕️ モダンな論理プロパティで指定する */<br>
    <span class="hl-blue">.badge-modern</span> {<br>
      <span class="hl-green">position: absolute;</span><br>
      <span class="hl-comment">/* 💡 block-start = 通常は「上」。縦書きなら「右」になる */</span><br>
      <span class="hl-red">inset-block-start: 15px;</span><br>
    <br>
      <span class="hl-comment">/* 💡 inline-start = 通常は「左」。アラビア語なら「右」になる */</span><br>
      <span class="hl-red">inset-inline-start: 15px;</span><br>
    }
  </div>
</div>
CSSコード表示
.inset-logical-container {
  position: relative;
  width: 100%;
  max-width: 400px;
  height: 200px;
  background-color: #fff;
  border: 2px solid #ced4da;
  border-radius: 8px;
  /* 言語の方向を示すダミーテキスト */
  display: flex;
  align-items: center;
  justify-content: center;
  color: #adb5bd;
  font-size: 24px;
  font-weight: bold;
}

.inset-logical-container::before {
  content: "Main Content Area";
}

/* =💡 実践コード:論理プロパティを使ったバッジ配置= */
.inset-logical-item {
  position: absolute;
  /* 💡 top: 15px; と同じ意味合いだが、多言語に強い */
  inset-block-start: 15px;
  /* 💡 left: 15px; と同じ意味合いだが、多言語に強い */
  inset-inline-start: 15px;
  
  background-color: #dc3545;
  color: white;
  padding: 8px 15px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: bold;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

box-shadowのinsetで内側の影(凹み)を作る

Webデザインにおいて、要素を「浮き上がらせる」のではなく、「ポコッと凹ませる」「彫り込まれたような立体感を出す」ために使われるのが、bo-x-shadowinsetです。

通常、box-shadowは要素の外側に影を落としますが、値にinsetというキーワードを一つ追加するだけで、影の向きが内側に反転します。

この仕組みを理解すれば、押し込まれたボタンや入力フォームの深い溝などが作れます。

ここでは、外側シャドウとの違い、一部の方向だけに影をつける、テキストへの応用や便利ツールまで解説します。

box-shadowのinsetで内側の影(凹み)を作る
  • 基本的な内側シャドウとoutsetとの違い
  • 上だけ・下だけなど一部の方向にinsetの影をつける
  • text-shadowfilterでの表現と便利ジェネレーター

基本的な内側シャドウとoutsetとの違い

box-shadowを使う際、通常我々が書いている影は「外側」に向かって伸びています。

これを「outset(アウトセット)」と呼びますが、CSSの文法としてoutsetというキーワードを直接書くことはありません。

これに対して、影を内側に落としたい場合は、プロパティの値の先頭(または末尾)にinsetと明記します。

内側の影(inset)を見せるには、「不透明度を0.1 〜 0.15程度の極めて薄い値に設定すること」です。

また、ハイライト(白い影)と組み合わせることで、近年流行したニューモーフィズムのような立体的で柔らかい凹みを表現できます。

⭕️ inset を付けるだけで「浮き上がり」が「凹み」に変わる!

外側シャドウ(通常)
要素が浮き上がって見える

OUTSET

内側シャドウ(inset)
要素が押し込まれて見える

INSET
/* ❌ 影が濃すぎると汚れに見えるため注意 */

/* 💡 通常の外側シャドウ(outsetとは書かない) */
.box-normal {
  /* X軸(5px) Y軸(5px) ぼかし(15px) 広がり(0) 色 */
  box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.15);
}

/* ⭕️ inset は極めて薄い不透明度(0.15など)で上品にかける */
.box-inset {
  /* 💡 先頭に inset を付けるだけで内側になる */
  box-shadow: inset 5px 5px 15px rgba(0, 0, 0, 0.15);
}
HTMLコード表示
<div class="bs-layout-wrapper">
  <p class="bs-caption">⭕️ inset を付けるだけで「浮き上がり」が「凹み」に変わる!</p>

  <div class="bs-demo-area">
    
    <div class="bs-box-wrapper">
      <p class="bs-label">外側シャドウ(通常)<br><small>要素が浮き上がって見える</small></p>
      <div class="bs-box is-outset">OUTSET</div>
    </div>

    <div class="bs-box-wrapper">
      <p class="bs-label" style="color:#0d6efd;">内側シャドウ(inset)<br><small>要素が押し込まれて見える</small></p>
      <div class="bs-box is-inset">INSET</div>
    </div>

  </div>

  <div class="bs-code-area">
    /* ❌ 影が濃すぎると汚れに見えるため注意 */<br><br>

    /* 💡 通常の外側シャドウ(outsetとは書かない) */<br>
    <span class="hl-blue">.box-normal</span> {<br>
      <span class="hl-comment">/* X軸(5px) Y軸(5px) ぼかし(15px) 広がり(0) 色 */</span><br>
      <span class="hl-green">box-shadow:</span> <span class="hl-red">5px 5px 15px rgba(0, 0, 0, 0.15);</span><br>
    }<br><br>

    /* ⭕️ inset は極めて薄い不透明度(0.15など)で上品にかける */<br>
    <span class="hl-blue">.box-inset</span> {<br>
      <span class="hl-comment">/* 💡 先頭に inset を付けるだけで内側になる */</span><br>
      <span class="hl-green">box-shadow:</span> <span class="hl-red">inset 5px 5px 15px rgba(0, 0, 0, 0.15);</span><br>
    }
  </div>
</div>
CSSコード表示
.bs-layout-wrapper {
  background-color: #f8f9fa;
  padding: 30px;
  border-radius: 8px;
  border: 1px solid #dee2e6;
}

.bs-caption {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 30px;
  color: #198754;
  text-align: center;
}

.bs-demo-area {
  display: flex;
  justify-content: center;
  gap: 40px;
  background-color: #e9ecef;
  padding: 50px 20px;
  border-radius: 8px;
  border: 1px dashed #adb5bd;
  margin-bottom: 20px;
}

.bs-box-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.bs-label {
  font-size: 13px;
  font-weight: bold;
  color: #333;
  margin-bottom: 20px;
  text-align: center;
  line-height: 1.5;
}

/* 共通のボックス形状 */
.bs-box {
  width: 120px;
  height: 120px;
  background-color: #e9ecef; /* 背景色と同じにして影を際立たせる */
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: #6c757d;
  border-radius: 20px;
  font-size: 18px;
}

/* =💡 実践コード:外側シャドウ= */
.is-outset {
  /* 浮き上がって見えるように白と黒の影を重ねる(ニューモーフィズム風) */
  box-shadow: 
    8px 8px 16px rgba(0, 0, 0, 0.1), 
    -8px -8px 16px rgba(255, 255, 255, 0.8);
}

/* =💡 実践コード:内側シャドウ(inset)= */
.is-inset {
  color: #0d6efd;
  /* 凹んで見えるように白と黒の影を内側に重ねる */
  box-shadow: 
    inset 8px 8px 16px rgba(0, 0, 0, 0.1), 
    inset -8px -8px 16px rgba(255, 255, 255, 0.8);
}

.bs-code-area {
  background-color: #282c34;
  color: #abb2bf;
  padding: 20px;
  border-radius: 6px;
  font-family: monospace;
  font-size: 13px;
  line-height: 1.6;
  border-left: 4px solid #0d6efd;
}

.hl-blue { color: #61afef; font-weight: bold; }
.hl-red { color: #e06c75; font-weight: bold; }
.hl-green { color: #98c379; font-weight: bold; }
.hl-comment { color: #6c757d; font-style: italic; }

box-shadowの使い方を詳しく知りたい人は「【CSS】box-shadowの使い方:おしゃれな影のコピペ集と浮遊感の作り方」を一読ください。

上だけ・下だけなど一部の方向にinsetの影をつける

「ボックスの『下側』にだけ深い溝のような影をつけたい」という要望は、ヘッダーの境界線やボタンを押し込んだ時の表現などでよく発生します。

「下だけ」にシャドウを付けたいのに、左右にもうっすらと影が漏れてしまうことがあります。

これを防ぐためには、「広がりの値をマイナスにする」ことです。

ぼかしと同じかそれ以上のマイナス値を広がりに設定することで、左右や上部の不要な影を隠し、狙った一面だけにシャドウを落とせます。

⭕️ 「下だけ」に影をつけるなら、Y軸はマイナス!Spreadで左右の漏れを防ぐ

❌ 左右に影が漏れている

Bottom Shadow

⭕️ Spreadをマイナス指定
(下部だけにクッキリ落ちる)

Bottom Only
/* ❌ ぼかした影が左右にもはみ出してしまう */
.shadow-leak {
  /* Y軸をマイナス(-15px)にして下から影を出しているが… */
  box-shadow: inset 0 -15px 15px rgba(0,0,0, 0.2);
}

/* ⭕️ 第4の値(広がり=Spread)をマイナスにして漏れを隠す! */
.shadow-clean-bottom {
  /* inset | X軸 | Y軸 | ぼかし | 広がり(マイナス) | 色 */
  box-shadow: inset 0 -15px 15px -10px rgba(0,0,0, 0.4);
}
HTMLコード表示
<div class="bs-layout-wrapper">
  <p class="bs-caption">⭕️ 「下だけ」に影をつけるなら、Y軸はマイナス!Spreadで左右の漏れを防ぐ</p>

  <div class="bs-demo-area" style="align-items: stretch;">
    
    <div class="bs-box-wrapper" style="flex: 1; max-width: 220px;">
      <p class="bs-label">❌ 左右に影が漏れている</p>
      <div class="bs-dir-box is-leaking">
        Bottom Shadow
      </div>
    </div>

    <div class="bs-box-wrapper" style="flex: 1; max-width: 220px;">
      <p class="bs-label" style="color:#0d6efd;">⭕️ Spreadをマイナス指定<br><small>(下部だけにクッキリ落ちる)</small></p>
      <div class="bs-dir-box is-clean-bottom">
        Bottom Only
      </div>
    </div>

  </div>

  <div class="bs-code-area">
    /* ❌ ぼかした影が左右にもはみ出してしまう */<br>
    <span class="hl-blue">.shadow-leak</span> {<br>
      <span class="hl-comment">/* Y軸をマイナス(-15px)にして下から影を出しているが... */</span><br>
      <span class="hl-green">box-shadow:</span> <span class="hl-red">inset 0 -15px 15px rgba(0,0,0, 0.2);</span><br>
    }<br><br>

    /* ⭕️ 第4の値(広がり=Spread)をマイナスにして漏れを隠す! */<br>
    <span class="hl-blue">.shadow-clean-bottom</span> {<br>
      <span class="hl-comment">/* inset | X軸 | Y軸 | ぼかし | 広がり(マイナス) | 色 */</span><br>
      <span class="hl-green">box-shadow:</span> <span class="hl-red">inset 0 -15px 15px -10px rgba(0,0,0, 0.4);</span><br>
    }
  </div>
</div>
CSSコード表示
.bs-layout-wrapper {
  background-color: #f8f9fa;
  padding: 30px;
  border-radius: 8px;
  border: 1px solid #dee2e6;
}

.bs-caption {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 30px;
  color: #198754;
  text-align: center;
}

.bs-demo-area {
  display: flex;
  justify-content: center;
  gap: 40px;
  background-color: #e9ecef;
  padding: 50px 20px;
  border-radius: 8px;
  border: 1px dashed #adb5bd;
  margin-bottom: 20px;
}

.bs-box-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.bs-label {
  font-size: 13px;
  font-weight: bold;
  color: #333;
  margin-bottom: 20px;
  text-align: center;
  line-height: 1.5;
}

/* =ボックスの基本形状= */
.bs-dir-box {
  width: 100%;
  max-width: 180px;
  height: 80px;
  background-color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: #333;
  border-radius: 8px;
  border: 1px solid #ced4da;
  margin-top: auto; 
}

/* =❌ 実践コード:左右に漏れる影= */
.is-leaking {
  box-shadow: inset 0 -15px 15px rgba(0, 0, 0, 0.2);
}

/* =⭕️ 実践コード:Spreadのマイナスで下だけにする= */
.is-clean-bottom {
  box-shadow: inset 0 -15px 15px -10px rgba(0, 0, 0, 0.4);
  color: #0d6efd;
  border-color: #0d6efd;
}

.bs-code-area {
  background-color: #282c34;
  color: #abb2bf;
  padding: 20px;
  border-radius: 6px;
  font-family: monospace;
  font-size: 13px;
  line-height: 1.6;
  border-left: 4px solid #0d6efd;
}

.hl-blue { color: #61afef; font-weight: bold; }
.hl-red { color: #e06c75; font-weight: bold; }
.hl-green { color: #98c379; font-weight: bold; }
.hl-comment { color: #6c757d; font-style: italic; }

text-shadowやfilterでの表現と便利ジェネレーター

例えば、テキストを凹ませる「レタープレス(活版印刷)効果」を作りたい場合、text-shadowの「外側シャドウ」を利用します。

文字色を背景より少し暗くし、その下方向(Y軸プラス方向)に白いハイライトを落とすことで、人間の目には「文字が彫り込まれている」ように錯覚して見えます。

また、複雑なbox-shadowを手書きで調整するのは時間の無駄です。

実務では、直感的に影をデザインできるWeb上の無料ツールを活用し、出力されたコードをコピペするのが楽です。

⭕️ text-shadowにはinsetが使えない!「白い影」を下に落として凹みを錯覚させる

レタープレス(活版印刷)風のテキスト

INSET TEXT EFFECT
/* 🚨 警告:text-shadow や drop-shadow では inset は使えません! */
.error-text {
  text-shadow: inset 1px 1px 2px #000; /* 完全に無視されます */
}

/* ⭕️ 文字色を暗くし、その「下」に白い光を落とす錯覚テクニック */
.letterpress-text {
  background-color: #ced4da; /* 💡 やや暗めの背景に配置する */
  color: #aeb5bc; /* 💡 文字色は背景よりもさらに少し暗くする */

  /* 💡 右下(1px 1px)に、純白(rgba 255)の影を落とす */
  text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.8);
}
HTMLコード表示
<div class="bs-layout-wrapper">
  <p class="bs-caption">⭕️ text-shadowにはinsetが使えない!「白い影」を下に落として凹みを錯覚させる</p>

  <div class="bs-demo-area" style="background-color: #ced4da;">
    
    <div class="bs-box-wrapper" style="width: 100%;">
      <p class="bs-label">レタープレス(活版印刷)風のテキスト</p>
      
      <div class="bs-letterpress-text">INSET TEXT EFFECT</div>
      
    </div>

  </div>

  <div class="bs-code-area">
    /* 🚨 警告:text-shadow や drop-shadow では inset は使えません! */<br>
    <span class="hl-blue">.error-text</span> {<br>
      <span class="hl-red">text-shadow: inset 1px 1px 2px #000;</span> /* 完全に無視されます */<br>
    }<br><br>

    /* ⭕️ 文字色を暗くし、その「下」に白い光を落とす錯覚テクニック */<br>
    <span class="hl-blue">.letterpress-text</span> {<br>
      <span class="hl-green">background-color: #ced4da;</span> /* 💡 やや暗めの背景に配置する */<br>
      <span class="hl-green">color: #aeb5bc;</span> /* 💡 文字色は背景よりもさらに少し暗くする */<br>
    <br>
      <span class="hl-comment">/* 💡 右下(1px 1px)に、純白(rgba 255)の影を落とす */</span><br>
      <span class="hl-green">text-shadow:</span> <span class="hl-red">1px 1px 1px rgba(255, 255, 255, 0.8);</span><br>
    }
  </div>
</div>
CSSコード表示
/* =💡 実践コード:テキストを凹ませる錯覚(レタープレス)= */
.bs-letterpress-text {
  font-family: 'Arial Black', sans-serif;
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 2px;
  margin: 0;
  
  /* 1. 文字色は背景(#ced4da)よりも少しだけ暗くする */
  color: #aeb5bc;
  
  /* 2. 右下(X:1px, Y:1px)に向かって、白いハイライト(光)を落とす */
  /* これにより、光が当たっている窪みのフチが表現され、凹んで見える */
  text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.9);
}

/* レスポンシブ対応 */
@media (max-width: 600px) {
  .bs-letterpress-text {
    font-size: 24px;
  }
}

border・outlineの立体化とclip-pathの切り抜き

CSSにおける「inset」というキーワードは、配置や影だけで使われるものではありません。

要素の「枠線」を立体的に見せたり、画像を自由な形で切り抜く「clip-path」という別プロパティでも重要な役割を持っています。

ここでは、insetを用いた立体的な枠線の作り方、CSSアニメーションで活躍するclip-pathの切り抜きまで解説します。

border・outlineの立体化とclip-pathの切り抜き
  • border-style: inset;で作る凹んだ枠線と角丸
  • clip-path: inset()を使った要素の四角い切り抜き

border-style: inset;で作る凹んだ枠線と角丸

CSSの枠線を指定する際、実線(solid)や点線(dashed)が一般的ですが、border-styleにはinsetoutsetという立体的なスタイルが用意されています。

モダンなWebデザインでborder-style: inset;を使う場合は、「枠線を1px〜2px程度の極細にし、背景色と馴染む淡い色を指定すること」です。

これにより、悪目立ちしない押し込み効果を作れます。

また、角丸と組み合わせることで、入力フォームの自然な凹み表現など、現代的なUIデザインに昇華できます。

⭕️ inset枠線は「極細×角丸」で使うのがモダンデザインの鉄則

❌ 太い inset
(昔のWebサイト風)

OLD UI

💡 outset
(出っ張った枠線)

OUTSET

⭕️ 極細角丸の inset
(今風のフォームの凹み)

/* ❌ 枠線が太いと一気に古臭くなる */
.old-inset {
  border-width: 6px;
  border-style: inset;
  border-color: #ccc;
}

/* ⭕️ 極細の 1px 〜 2px と border-radius を組み合わせる */
.modern-inset {
  border-width: 2px;
  border-style: inset;
  border-color: #e9ecef;
  border-radius: 8px; /* 💡 角丸と組み合わせるのが現代の定石 */
  background-color: #f8f9fa;
}
HTMLコード表示
<div class="bd-layout-wrapper">
  <p class="bd-caption">⭕️ inset枠線は「極細×角丸」で使うのがモダンデザインの鉄則</p>

  <div class="bd-demo-area">
    
    <div class="bd-box-wrapper">
      <p class="bd-label">❌ 太い inset<br><small>(昔のWebサイト風)</small></p>
      <div class="bd-element is-bad-inset">OLD UI</div>
    </div>

    <div class="bd-box-wrapper">
      <p class="bd-label">💡 outset<br><small>(出っ張った枠線)</small></p>
      <div class="bd-element is-modern-outset">OUTSET</div>
    </div>

    <div class="bd-box-wrapper">
      <p class="bd-label bd-text-blue">⭕️ 極細角丸の inset<br><small>(今風のフォームの凹み)</small></p>
      <input type="text" class="bd-element is-modern-inset" value="INPUT FIELD" readonly>
    </div>

  </div>

  <div class="bd-code-area">
    /* ❌ 枠線が太いと一気に古臭くなる */<br>
    <span class="hl-blue">.old-inset</span> {<br>
      <span class="hl-green">border-width:</span> <span class="hl-red">6px;</span><br>
      <span class="hl-green">border-style:</span> <span class="hl-red">inset;</span><br>
      <span class="hl-green">border-color:</span> <span class="hl-red">#ccc;</span><br>
    }<br><br>

    /* ⭕️ 極細の 1px 〜 2px と border-radius を組み合わせる */<br>
    <span class="hl-blue">.modern-inset</span> {<br>
      <span class="hl-green">border-width:</span> <span class="hl-red">2px;</span><br>
      <span class="hl-green">border-style:</span> <span class="hl-red">inset;</span><br>
      <span class="hl-green">border-color:</span> <span class="hl-red">#e9ecef;</span><br>
      <span class="hl-green">border-radius:</span> <span class="hl-red">8px;</span> /* 💡 角丸と組み合わせるのが現代の定石 */<br>
      <span class="hl-green">background-color:</span> <span class="hl-red">#f8f9fa;</span><br>
    }
  </div>
</div>
CSSコード表示
.bd-layout-wrapper {
  background-color: #f8f9fa;
  padding: 30px;
  border-radius: 8px;
  border: 1px solid #dee2e6;
}

.bd-caption {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 30px;
  color: #198754;
  text-align: center;
}

.bd-demo-area {
  display: flex;
  justify-content: center;
  gap: 30px;
  background-color: #e9ecef;
  padding: 40px;
  border-radius: 8px;
  border: 1px dashed #adb5bd;
  margin-bottom: 20px;
}

.bd-box-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.bd-label {
  font-size: 13px;
  font-weight: bold;
  color: #333;
  margin-bottom: 15px;
  text-align: center;
  line-height: 1.5;
}

.bd-text-blue {
  color: #0d6efd;
}

/* 共通の要素ベース */
.bd-element {
  width: 120px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
  color: #6c757d;
  background-color: #ced4da;
  box-sizing: border-box;
  text-align: center;
}

/* =❌ 実践コード:古臭いinset= */
.is-bad-inset {
  border-width: 6px;
  border-style: inset;
  border-color: #adb5bd;
}

/* =💡 実践コード:モダンなoutset= */
.is-modern-outset {
  border-width: 3px;
  border-style: outset;
  border-color: #dee2e6;
  border-radius: 8px; /* 角丸を効かせる */
  background-color: #e9ecef;
}

/* =⭕️ 実践コード:モダンな角丸inset(入力フォーム風)= */
.is-modern-inset {
  border-width: 2px;
  border-style: inset;
  border-color: #dee2e6;
  border-radius: 8px; /* 角丸を効かせる */
  background-color: #f8f9fa;
  outline: none; /* フォーカス時の青枠を消す */
}

.bd-code-area {
  background-color: #282c34;
  color: #abb2bf;
  padding: 20px;
  border-radius: 6px;
  font-family: monospace;
  font-size: 13px;
  line-height: 1.6;
  border-left: 4px solid #0d6efd;
}

.hl-blue { color: #61afef; font-weight: bold; }
.hl-red { color: #e06c75; font-weight: bold; }
.hl-green { color: #98c379; font-weight: bold; }

clip-path: inset()を使った要素の四角い切り抜き

CSSで要素を好きな形にくり抜くことができるclip-pathプロパティがあります。

その中で、要素を「四角形」に切り抜く関数がinset()です。

「上下左右の端から、内側に向かってどれだけ削り取るか」を指定するもので、アニメーションと組み合わせることで「画像がスッと現れる」ようなワイプ表現を作る際に重宝します。

clip-path: inset()を使う際に角丸をつけたい場合は、プロパティの中に専用のroundを記述するのがルールです。

clip-path: inset(10% 10% 10% 10% round 20px);のように、切り取る値の最後にround 角丸の数値を書き足すことで、切り抜かれた領域自体に角丸を付与できます。

⭕️ clip-pathで切り抜く時の「角丸」は、roundキーワードを使うのが鉄則!

元の状態
(100%のサイズ)

Original

❌ border-radius指定
(鋭角に切り落とされる)

Clipped

⭕️ round キーワード指定
(切り抜き領域が丸くなる)

round 20px
/* ❌ clip-pathを使うと、通常の border-radius は切り落とされて消える */
.clip-wrong {
  border-radius: 20px; /* 💡 無効化されてしまう */
  clip-path: inset(15px 15px 15px 15px); /* 💡 上下左右を15px削る */
}

/* ⭕️ clip-path の inset() の中で「round」キーワードを使う */
.clip-correct {
  clip-path: inset(15px 15px 15px 15px round 20px); /* 💡 最後に round 20px を追加! */
}
HTMLコード表示
<div class="bd-layout-wrapper">
  <p class="bd-caption">⭕️ clip-pathで切り抜く時の「角丸」は、roundキーワードを使うのが鉄則!</p>

  <div class="bd-demo-area">
    
    <div class="bd-box-wrapper">
      <p class="bd-label">元の状態<br><small>(100%のサイズ)</small></p>
      <div class="bd-clip-base">
        Original
      </div>
    </div>

    <div class="bd-box-wrapper">
      <p class="bd-label">❌ border-radius指定<br><small>(鋭角に切り落とされる)</small></p>
      <div class="bd-clip-base is-clipped-wrong">
        Clipped
      </div>
    </div>

    <div class="bd-box-wrapper">
      <p class="bd-label bd-text-blue">⭕️ round キーワード指定<br><small>(切り抜き領域が丸くなる)</small></p>
      <div class="bd-clip-base is-clipped-correct">
        round 20px
      </div>
    </div>

  </div>

  <div class="bd-code-area">
    /* ❌ clip-pathを使うと、通常の border-radius は切り落とされて消える */<br>
    <span class="hl-blue">.clip-wrong</span> {<br>
      <span class="hl-green">border-radius:</span> <span class="hl-red">20px;</span> /* 💡 無効化されてしまう */<br>
      <span class="hl-green">clip-path:</span> <span class="hl-red">inset(15px 15px 15px 15px);</span> /* 💡 上下左右を15px削る */<br>
    }<br><br>

    /* ⭕️ clip-path の inset() の中で「round」キーワードを使う */<br>
    <span class="hl-blue">.clip-correct</span> {<br>
      <span class="hl-green">clip-path:</span> <span class="hl-red">inset(15px 15px 15px 15px round 20px);</span> /* 💡 最後に round 20px を追加! */<br>
    }
  </div>
</div>
CSSコード表示
.bd-clip-base {
  width: 140px;
  height: 140px;
  background: linear-gradient(135deg, #6f42c1, #0d6efd);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: white;
  font-size: 14px;
}

/* =❌ 実践コード:border-radius が消える= */
.is-clipped-wrong {
  border-radius: 20px; /* 指定しているが... */
  clip-path: inset(20px 20px 20px 20px); /* スパッと四角く切り落とされるため角丸が消える */
}

/* =⭕️ 実践コード:round キーワードを使う= */
.is-clipped-correct {
  /* 上下左右を20pxずつ削り、その削った輪郭に対して20pxの角丸をつける */
  clip-path: inset(20px 20px 20px 20px round 20px); 
}

切り抜きで利用するclip-pathの使い方を詳しく知りたい人は「【CSS】clip-pathの使い方:図形の切り抜きと影・枠線の付け方」を一読ください。

スマホのノッチ・ホームバー対応:safe-area-inset

Webアプリやスマホ向けサイトを制作する際、避けては通れないのがsafe-area-insetの対応です。

iPhone X以降の全画面ディスプレイ端末に登場した「ノッチ(画面上部の切り欠き)」や「ダイナミックアイランド」、画面下部にある「ホームバー(ホームインジケーター)」などがあります。

これらを考慮せずにヘッダーやフッターを画面の端に固定配置してしまうと、大事なボタンがホームバーと重なってタップできなかったり、文字がノッチに隠れて読めなくなったりする致命的なユーザビリティの低下を招きます。

この問題をCSSだけで解決するのが、ブラウザが提供する環境変数env()を使ったセーフエリアの確保です。

スマホのノッチ・ホームバー対応:safe-area-inset
  • envの使い方と余白設定

envの使い方と余白設定

スマホ画面の上下に要素を固定配置する際、上部のノッチ領域を避けるためにsafe-area-inset-top、下部のホームバー領域を避けるためにsafe-area-inset-bottomを使用します。

具体的には、要素のpaddingenv(safe-area-inset-bottom)のように指定することで、ブラウザが「端末固有の安全な余白サイズ」を自動的に計算して適用してくれます。

  1. 最大の盲点viewport-fit=cover
    CSSでどれだけenv()を書いても、HTMLの<head>内にある viewport metaタグにviewport-fit=coverを追記していないと、iOSはセーフエリアの計算を無視します。
    「コードは合っているのに効かない!」という原因のほとんどはこれです。
  2. 非対応端末でのレイアウト崩壊
    padding-bottom: env(safe-area-inset-bottom);とだけ記述し、最新のiPhoneで確認して満足してしまうミスです。
    この記述のまま、ホームボタンのある古いiPhoneや一部のAndroid端末で表示すると、env()の値が0pxとして処理されます。
    結果として、ボタンが画面の最下部に張り付いてしまい、不格好で押しづらいUIになってしまいます。

実務におけるセーフエリア対応は、CSSのmax()関数と組み合わせることです。

padding-bottom: max(16px, env(safe-area-inset-bottom));と記述することで、「セーフエリアがない端末では最低でも16pxの余白を確保し、ホームバーがある端末ではホームバーの高さ(例: 34px)を採用する」という、どんな端末でも崩れないレイアウトを作れます。

⭕️ iPhone特有の「ダイナミックアイランド」や「ホームバー」を安全に回避する

VISION

次世代のイノベーションを、
あなたの手元へ。

NEWS
  • 2026.05.01新サービスをリリースしました
  • 2026.04.28コーポレートサイトを刷新
  • 2026.04.15東京オフィス移転のお知らせ
  • 2026.03.10採用情報を更新しました
  • 2026.02.05年末年始の休業について
SERVICES
Web Consulting
Cloud Integration
UI/UX Design
/* ⭕️ 固定ヘッダー(上部のカメラを避ける) */
.header {
  position: fixed;
  top: 0;
  /* 💡 env()が効かない環境用に最低15pxを確保し、iPhone等ではノッチの高さ(約47px)を採用 */
  padding-top: max(15px, env(safe-area-inset-top));
}

/* ⭕️ 固定フッター(下部のホームバーを避ける) */
.footer {
  position: fixed;
  bottom: 0;
  /* 💡 古いスマホでは最低15pxを確保し、iPhoneX以降はホームバーの高さ(約34px)を採用 */
  padding-bottom: max(15px, env(safe-area-inset-bottom));
}
HTMLコード表示
<div class="safe-layout-wrapper">
  
  <p class="safe-caption">⭕️ iPhone特有の「ダイナミックアイランド」や「ホームバー」を安全に回避する</p>

  <div class="safe-demo-area">
    
    <div class="corp-iphone-device">
      
      <div class="corp-iphone-island"></div>
      
      <header class="corp-app-header">
        <div class="corp-logo">ACME Corp.</div>
        <div class="corp-menu-icon">☰</div>
      </header>

      <main class="corp-app-main">
        <div class="corp-hero">
          <div>VISION</div>
          <p>次世代のイノベーションを、<br>あなたの手元へ。</p>
        </div>
        
        <section class="corp-section">
          <div class="corp-sec-title">NEWS</div>
          <ul class="corp-news-list">
            <li><span class="corp-date">2026.05.01</span><span class="corp-text">新サービスをリリースしました</span></li>
            <li><span class="corp-date">2026.04.28</span><span class="corp-text">コーポレートサイトを刷新</span></li>
            <li><span class="corp-date">2026.04.15</span><span class="corp-text">東京オフィス移転のお知らせ</span></li>
            <li><span class="corp-date">2026.03.10</span><span class="corp-text">採用情報を更新しました</span></li>
            <li><span class="corp-date">2026.02.05</span><span class="corp-text">年末年始の休業について</span></li>
          </ul>
        </section>

        <section class="corp-section">
          <div class="corp-sec-title">SERVICES</div>
          <div class="corp-card">Web Consulting</div>
          <div class="corp-card">Cloud Integration</div>
          <div class="corp-card">UI/UX Design</div>
        </section>
      </main>

      <nav class="corp-app-footer">
        <div class="corp-nav-item is-active"><span class="corp-nav-icon">🏢</span>HOME</div>
        <div class="corp-nav-item"><span class="corp-nav-icon">📦</span>SERVICE</div>
        <div class="corp-nav-item"><span class="corp-nav-icon">📰</span>NEWS</div>
        <div class="corp-nav-item"><span class="corp-nav-icon">✉️</span>CONTACT</div>
      </nav>
      
      <div class="corp-iphone-homebar"></div>

    </div>

  </div>

  <div class="safe-code-area">
    /* ⭕️ 固定ヘッダー(上部のカメラを避ける) */<br>
    <span class="hl-blue">.header</span> {<br>
      <span class="hl-green">position: fixed;</span><br>
      <span class="hl-green">top: 0;</span><br>
      <span class="hl-comment">/* 💡 env()が効かない環境用に最低15pxを確保し、iPhone等ではノッチの高さ(約47px)を採用 */</span><br>
      <span class="hl-red">padding-top: max(15px, env(safe-area-inset-top));</span><br>
    }<br><br>

    /* ⭕️ 固定フッター(下部のホームバーを避ける) */<br>
    <span class="hl-blue">.footer</span> {<br>
      <span class="hl-green">position: fixed;</span><br>
      <span class="hl-green">bottom: 0;</span><br>
      <span class="hl-comment">/* 💡 古いスマホでは最低15pxを確保し、iPhoneX以降はホームバーの高さ(約34px)を採用 */</span><br>
      <span class="hl-red">padding-bottom: max(15px, env(safe-area-inset-bottom));</span><br>
    }
  </div>

</div>
CSSコード表示
.safe-layout-wrapper {
  background-color: #f8f9fa;
  padding: 30px;
  border-radius: 8px;
  border: 1px solid #dee2e6;
}

.safe-caption {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 30px;
  color: #198754;
  text-align: center;
}

.safe-demo-area {
  display: flex;
  justify-content: center;
  background-color: #e9ecef;
  padding: 50px 20px;
  border-radius: 8px;
  border: 1px dashed #adb5bd;
  margin-bottom: 20px;
}

/* =📱 iPhoneモックアップ本体(最新モデル風比率&ベゼル)= */
.corp-iphone-device {
  position: relative;
  width: 320px;
  height: 600px; /* 少し高さを抑えて全体をスタイリッシュに */
  background-color: #fff;
  border: 14px solid #1c1c1e; /* リアルなベゼルの太さ */
  border-radius: 48px; /* iPhone特有の美しい角丸 */
  box-shadow: 0 25px 50px rgba(0,0,0,0.2), inset 0 0 0 2px #555;
  overflow: hidden; /* 画面外のはみ出しを隠す */
}

/* =💡 物理的なダイナミックアイランド= */
.corp-iphone-island {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 100px;
  height: 28px;
  background-color: #000;
  border-radius: 14px;
  z-index: 1000; /* 最前面 */
}

/* =💡 物理的なホームバー= */
.corp-iphone-homebar {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 4px;
  background-color: #1c1c1e;
  border-radius: 2px;
  z-index: 1000; /* 最前面 */
  pointer-events: none;
}

/* =⭕️ 実践コード1:上部固定ヘッダー= */
.corp-app-header {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  /* 今どきのすりガラス効果(backdrop-filter) */
  background-color: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(0,0,0,0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  z-index: 100;
  padding-left: 20px;
  padding-right: 20px;
  
  /* 💡 ここが鉄則!ダイナミックアイランドを避けるpadding */
  /* デモ表示用に、第1引数をアイランドより大きい値(50px)にしています */
  padding-top: max(50px, env(safe-area-inset-top));
  padding-bottom: 12px;
}

.corp-logo {
  font-size: 16px;
  font-weight: 900;
  color: #0a2540;
  letter-spacing: 0.5px;
}
.corp-menu-icon {
  font-size: 20px;
  color: #0a2540;
  cursor: pointer;
}

/* =💡 メインコンテンツ(スクロール領域)= */
.corp-app-main {
  height: 100%;
  overflow-y: auto;
  /* ヘッダーとフッターに隠れないための余白 */
  padding-top: 85px; 
  padding-bottom: 110px; 
  box-sizing: border-box;
  /* スクロールバーを非表示にする(スマホライク) */
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.corp-app-main::-webkit-scrollbar {
  display: none;
}

/* コーポレートサイト風デザイン */
.corp-hero {
  background: linear-gradient(135deg, #0a2540, #0055ff);
  color: #fff;
  padding: 40px 20px;
  margin-bottom: 30px;
}
.corp-hero h2 {
  font-size: 24px;
  margin: 0 0 10px 0;
  letter-spacing: 2px;
}
.corp-hero p {
  font-size: 13px;
  margin: 0;
  line-height: 1.6;
  opacity: 0.9;
}

.corp-section {
  padding: 0 20px;
  margin-bottom: 30px;
}
.corp-sec-title {
  font-size: 14px;
  color: #0a2540;
  border-bottom: 2px solid #0a2540;
  padding-bottom: 5px;
  margin: 0 0 15px 0;
}

.corp-news-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.corp-news-list li {
  font-size: 11px;
  border-bottom: 1px solid #e9ecef;
  padding: 10px 0;
  display: flex;
  gap: 10px;
}
.corp-date {
  color: #0055ff;
  font-weight: bold;
}
.corp-text {
  color: #495057;
}

.corp-card {
  background-color: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: bold;
  color: #333;
  text-align: center;
  box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}

/* =⭕️ 実践コード2:下部固定フッター= */
.corp-app-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background-color: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(0,0,0,0.08);
  display: flex;
  justify-content: space-around;
  box-sizing: border-box;
  z-index: 100;
  
  padding-top: 10px;
  /* 💡 ここが鉄則!ホームバーを避けるpadding */
  /* デモ表示用に、第1引数をホームバーより大きい値(25px)にしています */
  padding-bottom: max(25px, env(safe-area-inset-bottom));
}

.corp-nav-item {
  font-size: 10px;
  font-weight: bold;
  color: #adb5bd;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  flex: 1;
}
.corp-nav-item.is-active {
  color: #0055ff;
}
.corp-nav-icon {
  font-size: 18px;
}

.safe-code-area {
  background-color: #282c34;
  color: #abb2bf;
  padding: 20px;
  border-radius: 6px;
  font-family: monospace;
  font-size: 13px;
  line-height: 1.6;
  border-left: 4px solid #0d6efd;
}

.hl-blue { color: #61afef; font-weight: bold; }
.hl-red { color: #e06c75; font-weight: bold; }
.hl-green { color: #98c379; font-weight: bold; }
.hl-comment { color: #6c757d; font-style: italic; }

まとめ

分かりやすいようにまとめを記載します。

本記事のまとめ
  • insetプロパティはtoprightbottomleftを一括指定するショートハンドである。
  • 適用にはpositionプロパティ(absolutefixedなど)の指定が必須である。
  • inset: 0;margin: auto;および固定の幅・高さを組み合わせることで、絶対配置の中央寄せが成立する。
  • 縦書きや多言語対応を見据える場合、物理プロパティではなく論理プロパティ(inset-block/inset-inline)を使用する。
  • box-shadowinsetを付与すると内側シャドウ(凹み)になり、不透明度を0.15程度に抑えるのが推奨される。
  • 1辺のみに内側シャドウを落とす場合は、第4の値(広がり)をマイナスに設定して他の辺への漏れを防ぐ。
  • text-shadowfilter: drop-shadowの仕様にはinsetキーワードが存在せず、記述しても無効になる。
  • border-style: insetは、極細の線幅(1〜2px)とborder-radiusを併用することで現代的なUIとして成立する。
  • clip-path: inset()を用いた切り抜きで角丸を表現するには、値の末尾に専用のroundキーワードを指定する。
  • スマホのノッチやホームバー回避にはenv(safe-area-inset-*)を用い、非対応端末に備えてmax()関数と併用する。

よくある質問(FAQ)

CSSのinsetプロパティとは何ですか?

toprightbottomleftの4つのプロパティを1行でまとめて指定できるショートハンド(短縮記法)プロパティです。

position: absoluteposition: fixedと組み合わせて、要素を絶対配置する際の記述を短くできます。

insetで値を2つや3つ指定した場合、どの順番で適用されますか?

marginpaddingと同じルール(時計回り)が適用されます。

  • 値1つ(例: inset: 10px;)= 上下左右すべて
  • 値2つ(例: inset: 10px 20px;)= 「上下」と「左右」
  • 値3つ(例: inset: 10px 20px 30px;)= 「上」「左右」「下」
  • 値4つ(例: inset: 10px 20px 30px 40px;)= 「上」「右」「下」「左」
inset: 0;と指定すると画面が真っ暗になりました。なぜですか?

inset: 0;top: 0; right: 0; bottom: 0; left: 0;と同じ意味になり、「親要素の上下左右の端から0pxの位置にくっつく」という命令になります。

そのため、半透明の黒背景などに指定すると全画面に広がって画面を覆い尽くします。(モーダル背景などで使われる正しい挙動です。)

広げたくない場合はwidthheightでサイズを固定してください。

要素の位置を動かす際、insetとmarginのどちらを使えばいいですか?

目的によって明確に使い分けます。

ドキュメントの流れ(通常のレイアウト)の中で、他の要素との間に「余白」を作って押し退けたい場合はmarginを使います。

一方、position: absolute;などで通常のレイアウトから「浮かせた要素」を、親要素の枠を基準にして好きな位置に配置したい場合はinsetを使います。

insetプロパティはすべてのブラウザ(iPhoneや古いPCなど)で使えますか?

はい、現在のモダンブラウザ(Chrome、Edge、Safari、Firefoxの各最新版)や最新のスマートフォン環境では完全にサポートされており、実務で積極的に使用して問題ありません。

ただし、サポートが終了している Internet Explorer (IE11) では機能しないため、もしIE対応が必須の特殊な案件であれば、旧来のtopleftを分けて記述する必要があります。

この記事を書いた人

sugiのアバター sugi Site operator

【経歴】玉川大学工学部卒業→新卒SIer企業入社→2年半後に独立→プログラミングスクール運営/受託案件→フリーランスエンジニア&SEOコンサル→Python特化のコンテンツサイトJob Code&UIコピペサイトCode Stock運営中

目次