これは実験段階の機能です。
この機能は複数のブラウザで開発中の状態にあります。各ブラウザで用いるために、適切なベンダー接頭辞が必要な場合があります。互換性テーブルをチェックしてください。また、実験段階の機能の構文と挙動は、仕様変更に伴い各ブラウザの将来のバージョンで変更になる可能性があることに注意してください。
概要
CSS の perspective プロパティは、3D 配置された要素に遠近感を与えるため、z=0 平面とユーザ間の距離を決めます。z>0 である 3D 要素はより大きく、z<0 である 3D 要素はより小さくなります。効果の強度はこのプロパティの値から決められます。
ユーザの背後にある 3D 要素、例えば z-軸座標が perspective CSS プロパティの値より大きい要素は描画されません。
消失点はデフォルトで要素の中心に置かれますが、この位置は perspective-origin プロパティで変更できます。
このプロパティに 0 と none 以外の値を設定すると、新たなスタック文脈を作ります。
| 初期値 | none |
|---|---|
| 適用対象 | 変形可能要素 |
| 継承 | 不可 |
| メディア | visual |
| 計算値 | 絶対的な長さまたは none |
| アニメーションの可否 | 可。 の値として補完しますlength |
| 正規順序 | 形式文法で定義される一意のあいまいでない順序 |
| Creates stacking context | 継承する |
構文
/* キーワード値 */ perspective: none; /* <length> 値 */ perspective: 20px; perspective: 3.5em; /* グローバル値 */ perspective: inherit; perspective: initial; perspective: unset;
値
none- 立体的な変換を一切適用しないことを示すキーワードです。
<length>- ユーザと z=0 平面間の距離を表す
<length>です。立体的な変換を要素とその内容に適用するときに使います。0や 負の値なら、立体的な変換は適用されません。
形式文法
none | <length>
例
3 つの立方体
HTML コンテンツ
<table>
<tbody>
<tr>
<th><code>perspective: 250px;</code>
</th>
<th><code>perspective: 350px;</code>
</th>
<th><code>perspective: 500px;</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>
<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>
</tr>
</tbody>
</table>
CSS コンテンツ
/* さまざまな perspective の値のためのショートハンドクラス */
.pers250 {
perspective: 250px;
-webkit-perspective: 250px;
}
.pers350 {
perspective: 350px;
-webkit-perspective: 350px;
}
.pers500 {
perspective: 500px;
-webkit-perspective: 500px;
}
/* コンテナ 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;
-webkit-backface-visibility: visible;
-webkit-perspective-origin: 150% 150%;
-webkit-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);
-webkit-transform: translateZ(50px);
}
.back {
background: rgba(0, 255, 0, 1);
color: black;
transform: rotateY(180deg) translateZ(50px);
-webkit-transform: rotateY(180deg) translateZ(50px);
}
.right {
background: rgba(196, 0, 0, 0.7);
transform: rotateY(90deg) translateZ(50px);
-webkit-transform: rotateY(90deg) translateZ(50px);
}
.left {
background: rgba(0, 0, 196, 0.7);
transform: rotateY(-90deg) translateZ(50px);
-webkit-transform: rotateY(-90deg) translateZ(50px);
}
.top {
background: rgba(196, 196, 0, 0.7);
transform: rotateX(90deg) translateZ(50px);
-webkit-transform: rotateX(90deg) translateZ(50px)
}
.bottom {
background: rgba(196, 0, 196, 0.7);
transform: rotateX(-90deg) translateZ(50px);
-webkit-transform: rotateX(-90deg) translateZ(50px);
}
/* テーブルの見栄えをよくする */
th, p, td {
background-color: #EEEEEE;
padding: 10px;
font-family: sans-serif;
text-align: left;
}
結果
仕様
| 仕様書 | 策定状況 | コメント |
|---|---|---|
| CSS Transforms Level 1 perspective の定義 |
草案 |
ブラウザ実装状況
| 機能 | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
| 基本サポート | 12-webkit 45 |
10 (10)-moz 16 (16) |
10 | 15-webkit | (有)-webkit |
| 機能 | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| 基本サポート | 3.0-webkit | 10.0 (10)-moz 16.0 (16) |
8.1 | (有)-webkit | (有)-webkit |