3D / 102

CSS cube

CSSで組む立方体
平面の要素を三次元空間に配置し、立方体に見せます。

実際のHTML・CSSで描かれた見本です。

ラボで詳しく試す ↗

ひとつ試すなら

どこが変わるかを観察して、似た表現と見比べてみよう。

こんなときに

構造や立体感を説明する小さな図形。

仕組みと使い方

transform-styleで子要素の三次元配置を保ちます。

立方体cube3d立体
実装コードを見る
<style>
.sample{width:100%;height:100%;min-height:190px;display:grid;place-items:center;position:relative;overflow:hidden;box-sizing:border-box;font-family:Arial,'Hiragino Kaku Gothic ProN',Meiryo,sans-serif;color:#20211d;background:#f1f0e9;padding:22px}.sample *{box-sizing:border-box}.sample button,.sample input,.sample summary{font:inherit}.sample button,.sample summary,.sample label{touch-action:manipulation}.sample :focus-visible{outline:3px solid #6050bf;outline-offset:5px}.sample small{font-size:10px;line-height:1.5}.sample .editable{margin:0}.sample svg{max-width:100%;height:auto}
.sample .stage{perspective:500px}.sample .cube{width:95px;height:95px;position:relative;transform-style:preserve-3d;transform:rotateX(-22deg) rotateY(-33deg)}.sample i{position:absolute;width:95px;height:95px;border:1px solid #222;display:grid;place-items:center;font:900 52px Arial}.sample .front{background:#c9f537;transform:translateZ(47.5px)}.sample .right{background:#97b835;transform:rotateY(90deg) translateZ(47.5px)}.sample .top{background:#e2ff8c;transform:rotateX(90deg) translateZ(47.5px)}
</style>
<div class="sample">
<div class="stage"><div class="cube"><i class="front">g</i><i class="right"></i><i class="top"></i></div></div>
</div>