perspective-origin
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2015å¹´9æ.
perspective-origin 㯠CSS ã®ããããã£ã§ãé²è¦§è
ã®è¦ç¹ã®ä½ç½®ã決ãã¾ãããã㯠perspective ããããã£ã«ãã£ã¦ãæ¶ç¹ãã¨ãã¦ä½¿ããã¾ãã
試ãã¦ã¿ã¾ããã
perspective-origin: center;
perspective-origin: top;
perspective-origin: bottom right;
perspective-origin: -170%;
perspective-origin: 500% 200%;
<section class="default-example" id="default-example">
<div class="transition-all" id="example-element">
<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>
</section>
#default-example {
background: linear-gradient(skyblue, khaki);
perspective: 550px;
}
#example-element {
width: 100px;
height: 100px;
transform-style: preserve-3d;
perspective: 250px;
}
.face {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
position: absolute;
backface-visibility: inherit;
font-size: 60px;
color: white;
}
.front {
background: rgb(90 90 90 / 0.7);
transform: translateZ(50px);
}
.back {
background: rgb(0 210 0 / 0.7);
transform: rotateY(180deg) translateZ(50px);
}
.right {
background: rgb(210 0 0 / 0.7);
transform: rotateY(90deg) translateZ(50px);
}
.left {
background: rgb(0 0 210 / 0.7);
transform: rotateY(-90deg) translateZ(50px);
}
.top {
background: rgb(210 210 0 / 0.7);
transform: rotateX(90deg) translateZ(50px);
}
.bottom {
background: rgb(210 0 210 / 0.7);
transform: rotateX(-90deg) translateZ(50px);
}
perspective-origin ããã³ perspective ã®åããããã£ã¯ã䏿¬¡å
空éã§åº§æ¨å¤æãããåã®è¦ªã«è¨å®ãããã®ã§ããã座æ¨å¤æãããè¦ç´ ã«è¨å®ããã perspective() 夿颿°ã¨ã¯ç°ãªãã¾ãã
æ§æ
/* 1 夿§æ */
perspective-origin: x-position;
/* 2 夿§æ */
perspective-origin: x-position y-position;
/* x-position 㨠y-position ããã¼ã¯ã¼ãã§ããå ´åã¯ã
以ä¸ã®æ§æãæå¹ */
perspective-origin: y-position x-position;
/* ã°ãã¼ãã«å¤ */
perspective-origin: inherit;
perspective-origin: initial;
perspective-origin: revert;
perspective-origin: revert-layer;
perspective-origin: unset;
å¤
- x-position
-
æ¶ç¹ã®æ¨ªåº§æ¨ä¸ã®ä½ç½®ã示ãã¾ããæ¬¡ã®ããããã®å¤ã§ãã
<length-percentage>ã¯ã絶対ç㪠length å¤ãã¾ãã¯è¦ç´ ã®å¹ ã«å¯¾ããç¸å¯¾å¤ã§ä½ç½®ã示ãã¾ããè² ã®æ°ã使ãã¾ããleftãã¼ã¯ã¼ãã¯ãlength å¤0ã示ãã·ã§ã¼ãã«ããã§ããcenterãã¼ã¯ã¼ãã¯ããã¼ã»ã³ãå¤50%ã示ãã·ã§ã¼ãã«ããã§ããrightãã¼ã¯ã¼ãã¯ããã¼ã»ã³ãå¤100%ã示ãã·ã§ã¼ãã«ããã§ãã
- y-position
-
æ¶ç¹ã®ç¸¦åº§æ¨ä¸ã®ä½ç½®ã示ãã¾ããæ¬¡ã®ããããã®å¤ã§ãã
<length-percentage>ã¯ã絶対ç㪠length å¤ãã¾ãã¯è¦ç´ ã®é«ãã«å¯¾ããç¸å¯¾å¤ã§ä½ç½®ã示ãã¾ããè² ã®æ°ã使ãã¾ããtopãã¼ã¯ã¼ãã¯ã length å¤0ã示ãã·ã§ã¼ãã«ããã§ããcenterãã¼ã¯ã¼ãã¯ããã¼ã»ã³ãå¤50%ã示ãã·ã§ã¼ãã«ããã§ããbottomãã¼ã¯ã¼ãã¯ããã¼ã»ã³ãå¤100%ã示ããã¼ã¯ã¼ãã§ãã
å ¬å¼å®ç¾©
| åæå¤ | 50% 50% |
|---|---|
| é©ç¨å¯¾è±¡ | 座æ¨å¤æå¯è½è¦ç´ |
| ç¶æ¿ | ãªã |
| ãã¼ã»ã³ãå¤ | å²ã¿ããã¯ã¹ã®å¯¸æ³ã«å¯¾ããç¸å¯¾å¤ |
| è¨ç®å¤ | <length> ã®å ´åã¯çµ¶å¯¾çãªå¤ããã以å¤ã®å ´åã¯ãã¼ã»ã³ãå¤ |
| ã¢ãã¡ã¼ã·ã§ã³ã®ç¨®é¡ | é·ãããã¼ã»ã³ãå¤ã calc ã®åç´ãªãªã¹ã |
形弿æ³
perspective-origin =
<position>
<position> =
<position-one> |
<position-two> |
<position-four>
<position-one> =
left |
center |
right |
top |
bottom |
x-start |
x-end |
y-start |
y-end |
block-start |
block-end |
inline-start |
inline-end |
<length-percentage>
<position-two> =
[ left | center | right | x-start | x-end ] && [ top | center | bottom | y-start | y-end ] |
[ left | center | right | x-start | x-end | <length-percentage> ] [ top | center | bottom | y-start | y-end | <length-percentage> ] |
[ block-start | center | block-end ] && [ inline-start | center | inline-end ] |
[ start | center | end ]{2}
<position-four> =
[ [ left | right | x-start | x-end ] <length-percentage> ] && [ [ top | bottom | y-start | y-end ] <length-percentage> ] |
[ [ block-start | block-end ] <length-percentage> ] && [ [ inline-start | inline-end ] <length-percentage> ] |
[ [ start | end ] <length-percentage> ]{2}
<length-percentage> =
<length> |
<percentage>
ä¾
>è¦ç¹ã®åç¹ã®å¤æ´
perspective-origin ã®å¤æ´æ¹æ³ã示ãä¾ã¯ã CSS 座æ¨å¤æã®ä½¿ç¨ > è¦ç¹ã®å¤æ´ã«ããã¾ãã
仿§æ¸
| Specification |
|---|
| CSS Transforms Module Level 2> # perspective-origin-property> |