--- title: perspective slug: Web/CSS/perspective tags: - CSS - CSS プロパティ - CSS 変形 - Reference - グラフィック - プロパティ - 距離 translation_of: Web/CSS/perspective --- <div>{{CSSRef}}</div> <p><span class="seoSummary"><strong><code>perspective</code></strong> は <a href="/ja/docs/Web/CSS">CSS</a> のプロパティで、 z=0 の平面とユーザーとの間の距離を定めて三次元に配置された要素に遠近感を与えます。</span> z>0 である三次元要素はより大きく、 z<0 である三次元要素はより小さくなります。効果の強度はこのプロパティの値から決められます。</p> <div>{{EmbedInteractiveExample("pages/css/perspective.html")}}</div> <p class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</p> <p>ユーザーの背後にある 3D 要素の部品、つまり z 軸座標が CSS の <code>perspective</code> プロパティの値より大きい要素は描画されません。</p> <p><em>消失点</em>は既定で要素の中心に置かれますが、この位置は {{cssxref("perspective-origin")}} プロパティで変更できます。</p> <p>このプロパティを <code>0</code> と <code>none</code> 以外の値で使用すると、新たな<a href="/ja/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context">重ね合わせコンテキスト</a>を生成します。また、その場合、オブジェクトはそれを含む <code>position: fixed</code> の要素の包含ブロックとして動作します。</p> <h2 id="Syntax" name="Syntax">構文</h2> <pre class="brush: css">/* キーワード値 */ perspective: none; /* <length> 値 */ perspective: 20px; perspective: 3.5em; /* グローバル値 */ perspective: inherit; perspective: initial; perspective: unset; </pre> <h3 id="Values" name="Values">値</h3> <dl> <dt><code>none</code></dt> <dd>立体的な変形を一切適用しないことを示すキーワードです。</dd> <dt><code><length></code></dt> <dd>ユーザーと z=0 平面間の距離を表す {{cssxref("<length>")}} です。立体的な変形を要素とその内容に適用するときに使います。 <code>0</code> や負の値ならば、立体的な変形は適用されません。</dd> </dl> <h3 id="Formal_syntax" name="Formal_syntax">形式文法</h3> {{csssyntax}} <h2 id="Examples" name="Examples">例</h2> <h3 id="Setting_perspective" name="Setting_perspective">視点の設定</h3> <p>この例は様々な位置に視点が設定された立方体を表示します。どのように立方体が早く縮まるかは、 {{ cssxref("perspective") }} プロパティで定義されます。小さい値ほど、視点は近くなります。</p> <h4 id="Result" name="Result">結果</h4> <p>{{EmbedLiveSample('Setting_perspective', 660, 700)}}</p> <h4 id="HTML">HTML</h4> <p>以下の HTML は、4つの同じボックスのコピーを、様々な値の視点を設定して作成します。</p> <pre class="brush: html"><table> <tbody> <tr> <th><code>perspective: 250px;</code> </th> <th><code>perspective: 350px;</code> </th> </tr> <tr> <td> <div class="container"> <div class="cube pers250"> <div class="face front">1</div> <div class="face back">2</div> <div class="face right">3</div> <div class="face left">4</div> <div class="face top">5</div> <div class="face bottom">6</div> </div> </div> </td> <td> <div class="container"> <div class="cube pers350"> <div class="face front">1</div> <div class="face back">2</div> <div class="face right">3</div> <div class="face left">4</div> <div class="face top">5</div> <div class="face bottom">6</div> </div> </div> </td> </tr> <tr> <th><code>perspective: 500px;</code> </th> <th><code>perspective: 650px;</code> </th> </tr> <tr> <td> <div class="container"> <div class="cube pers500"> <div class="face front">1</div> <div class="face back">2</div> <div class="face right">3</div> <div class="face left">4</div> <div class="face top">5</div> <div class="face bottom">6</div> </div> </div> </td> <td> <div class="container"> <div class="cube pers650"> <div class="face front">1</div> <div class="face back">2</div> <div class="face right">3</div> <div class="face left">4</div> <div class="face top">5</div> <div class="face bottom">6</div> </div> </div> </td> </tr> </tbody> </table> </pre> <h4 id="CSS">CSS</h4> <p>様々な距離の遠近法を設定するために使用することができる CSS のクラスです。コンテナーボックスや立方体自身、それぞれの面のためのクラスも含みます。</p> <pre class="brush: css">/* さまざまな perspective の値のためのショートハンドクラス */ .pers250 { perspective: 250px; } .pers350 { perspective: 350px; } .pers500 { perspective: 500px; } .pers650 { perspective: 650px; } /* コンテナーの div、立方体の div、面の一般的な設定 */ .container { width: 200px; height: 200px; margin: 75px 0 0 75px; border: none; } .cube { width: 100%; height: 100%; backface-visibility: visible; perspective-origin: 150% 150%; transform-style: preserve-3d; } .face { display: block; position: absolute; width: 100px; height: 100px; border: none; line-height: 100px; font-family: sans-serif; font-size: 60px; color: white; text-align: center; } /* 方向に基づいてそれぞれの面を設定 */ .front { background: rgba(0, 0, 0, 0.3); transform: translateZ(50px); } .back { background: rgba(0, 255, 0, 1); color: black; transform: rotateY(180deg) translateZ(50px); } .right { background: rgba(196, 0, 0, 0.7); transform: rotateY(90deg) translateZ(50px); } .left { background: rgba(0, 0, 196, 0.7); transform: rotateY(-90deg) translateZ(50px); } .top { background: rgba(196, 196, 0, 0.7); transform: rotateX(90deg) translateZ(50px); } .bottom { background: rgba(196, 0, 196, 0.7); transform: rotateX(-90deg) translateZ(50px); } /* テーブルの見栄えをよくする */ th, p, td { background-color: #EEEEEE; padding: 10px; font-family: sans-serif; text-align: left; }</pre> <h2 id="Specifications" name="Specifications">仕様書</h2> <table class="standard-table"> <thead> <tr> <th scope="col">仕様書</th> <th scope="col">状態</th> <th scope="col">備考</th> </tr> </thead> <tbody> <tr> <td>{{Specname('CSS Transforms 2', '#propdef-perspective', 'perspective')}}</td> <td>{{Spec2('CSS Transforms 2')}}</td> <td>初回定義。</td> </tr> </tbody> </table> <p>{{cssinfo}}</p> <h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの対応</h2> <div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> <p>{{Compat("css.properties.perspective")}}</p> <h2 id="See_also" name="See_also">関連情報</h2> <ul> <li><a href="/ja/docs/Web/CSS/CSS_Transforms/Using_CSS_transforms">CSS 変形の使用</a></li> </ul>