9 CSS 3D Designs 05 / 09

Bauhaus Cube Navigator

A large drag-rotatable CSS 3D cube where each of the six genuine faces (built with translateZ + rotateX/Y) is a bold Bauhaus color block presenting a service category — Brand, Web, Motion, Space, Type, Print.

Best forproduct configurators, portfolio anchor sections, agency service navigators, interactive menus.

CSS + JS MIT licensed
Live Demo Open in tab
Open in playground

The code

<section class="cd-bcb" aria-label="Bauhaus 3D cube navigator demo">
  <div class="card">
    <div class="scene">
      <div class="cube" data-cd-bcb-cube>

        <div class="face face-front">
          <span class="face-num">01</span>
          <span class="face-tag">Visual Identity</span>
          <div class="face-label">Brand<br />System</div>
        </div>
        <div class="face face-back">
          <span class="face-num">02</span>
          <span class="face-tag">Digital Experience</span>
          <div class="face-label">Web<br />Design</div>
        </div>
        <div class="face face-left">
          <span class="face-num">03</span>
          <span class="face-tag">Creative Strategy</span>
          <div class="face-label">Motion<br />Art</div>
        </div>
        <div class="face face-right">
          <span class="face-num">04</span>
          <span class="face-tag">Environmental</span>
          <div class="face-label">Space<br />Design</div>
        </div>
        <div class="face face-top">
          <span class="face-num">05</span>
          <span class="face-tag">Systems Thinking</span>
          <div class="face-label">Type<br />Craft</div>
        </div>
        <div class="face face-bottom">
          <span class="face-num">06</span>
          <span class="face-tag">Material Culture</span>
          <div class="face-label">Print<br />Works</div>
        </div>

      </div>
    </div>

    <div class="controls" data-cd-bcb-controls>
      <button class="ctrl-btn active" type="button" data-face="front"  data-rx="-18" data-ry="22">Brand</button>
      <button class="ctrl-btn"        type="button" data-face="back"   data-rx="-18" data-ry="202">Web</button>
      <button class="ctrl-btn"        type="button" data-face="left"   data-rx="-18" data-ry="112">Motion</button>
      <button class="ctrl-btn"        type="button" data-face="right"  data-rx="-18" data-ry="-68">Space</button>
      <button class="ctrl-btn"        type="button" data-face="top"    data-rx="-108" data-ry="22">Type</button>
      <button class="ctrl-btn"        type="button" data-face="bottom" data-rx="72"  data-ry="22">Print</button>
    </div>

    <div class="auto-toggle" data-cd-bcb-autotoggle>
      <div class="toggle-track" data-cd-bcb-autotrack>
        <div class="toggle-thumb"></div>
      </div>
      <span>Auto-rotate</span>
    </div>

  </div>
</section>
/* ─── 05 Bauhaus Cube Navigator — drag-rotatable 3D cube ───── */
@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Space+Grotesk:wght@300;400;500;600&display=swap');

.cd-bcb {
  --cd-bcb-bg: #f0ede8;

  position: relative;
  width: 100%;
  min-height: 620px;
  background: var(--cd-bcb-bg);
  font-family: 'Space Grotesk', system-ui, sans-serif;
  overflow: hidden;
  box-sizing: border-box;
}

.cd-bcb *,
.cd-bcb *::before,
.cd-bcb *::after { box-sizing: border-box; margin: 0; padding: 0; }

.cd-bcb .card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
}
.cd-bcb .card::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4'%3E%3Crect width='1' height='1' x='0' y='0' fill='%23000' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
}

.cd-bcb .scene {
  perspective: 1400px;
  width: 320px;
  height: 320px;
  margin-bottom: 36px;
  position: relative;
  z-index: 1;
}

.cd-bcb .cube {
  width: 280px;
  height: 280px;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(-18deg) rotateY(22deg);
  transition: transform 0.85s cubic-bezier(0.23, 1, 0.32, 1);
  margin: 20px auto;
  will-change: transform;
  cursor: grab;
}
.cd-bcb .cube.dragging { cursor: grabbing; }

.cd-bcb .face {
  position: absolute;
  width: 280px;
  height: 280px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 24px;
  overflow: hidden;
  backface-visibility: visible;
}
.cd-bcb .face-front  { transform: translateZ(140px); }
.cd-bcb .face-back   { transform: rotateY(180deg) translateZ(140px); }
.cd-bcb .face-left   { transform: rotateY(-90deg) translateZ(140px); }
.cd-bcb .face-right  { transform: rotateY(90deg) translateZ(140px); }
.cd-bcb .face-top    { transform: rotateX(90deg) translateZ(140px); }
.cd-bcb .face-bottom { transform: rotateX(-90deg) translateZ(140px); }

.cd-bcb .face-front  { background: #e63b2e; }
.cd-bcb .face-back   { background: #2952cc; }
.cd-bcb .face-left   { background: #f0a500; }
.cd-bcb .face-right  { background: #1a8a4a; }
.cd-bcb .face-top    { background: #111111; }
.cd-bcb .face-bottom { background: #e8e2d8; }

.cd-bcb .face-front::before  { content: ''; position: absolute; top: -60px; right: -60px; width: 200px; height: 200px; border-radius: 50%; background: rgba(0,0,0,0.08); }
.cd-bcb .face-back::before   { content: ''; position: absolute; top: 20px; left: 20px; width: 0; height: 0; border-left: 110px solid transparent; border-right: 110px solid transparent; border-bottom: 180px solid rgba(255,255,255,0.06); }
.cd-bcb .face-left::before   { content: ''; position: absolute; inset: 20px; border: 2px solid rgba(0,0,0,0.1); }
.cd-bcb .face-right::before  { content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 140px; height: 140px; background: rgba(255,255,255,0.07); }
.cd-bcb .face-top::before    { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(45deg, rgba(255,255,255,0.03) 0, rgba(255,255,255,0.03) 1px, transparent 0, transparent 50%); background-size: 20px 20px; }
.cd-bcb .face-bottom::before { content: ''; position: absolute; inset: 0; background: radial-gradient(circle at 30% 30%, rgba(0,0,0,0.04) 0%, transparent 70%); }

.cd-bcb .face-label {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 56px;
  letter-spacing: 2px;
  line-height: 0.9;
  position: relative;
  z-index: 1;
}
.cd-bcb .face-tag {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 9px;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 7px;
  position: relative;
  z-index: 1;
  opacity: 0.65;
}
.cd-bcb .face-num {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 108px;
  position: absolute;
  top: -18px;
  right: 14px;
  opacity: 0.06;
  line-height: 1;
  letter-spacing: -4px;
}

.cd-bcb .face-front .face-label, .cd-bcb .face-front .face-tag,
.cd-bcb .face-back  .face-label, .cd-bcb .face-back  .face-tag,
.cd-bcb .face-right .face-label, .cd-bcb .face-right .face-tag,
.cd-bcb .face-top   .face-label, .cd-bcb .face-top   .face-tag { color: #fff; }
.cd-bcb .face-left  .face-label, .cd-bcb .face-left  .face-tag,
.cd-bcb .face-bottom .face-label, .cd-bcb .face-bottom .face-tag { color: #1a1000; }
.cd-bcb .face-bottom .face-label { color: #111; }

.cd-bcb .face::after {
  content: '';
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
  pointer-events: none;
}

.cd-bcb .controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 420px;
  position: relative;
  z-index: 1;
}
.cd-bcb .ctrl-btn {
  padding: 8px 16px 8px 22px;
  border: 2px solid #111;
  background: transparent;
  color: #111;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
  position: relative;
}
.cd-bcb .ctrl-btn::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cd-bcb-color);
}
.cd-bcb .ctrl-btn:hover,
.cd-bcb .ctrl-btn.active { background: #111; color: var(--cd-bcb-bg); }
.cd-bcb .ctrl-btn[data-face="front"]  { --cd-bcb-color: #e63b2e; }
.cd-bcb .ctrl-btn[data-face="back"]   { --cd-bcb-color: #2952cc; }
.cd-bcb .ctrl-btn[data-face="left"]   { --cd-bcb-color: #f0a500; }
.cd-bcb .ctrl-btn[data-face="right"]  { --cd-bcb-color: #1a8a4a; }
.cd-bcb .ctrl-btn[data-face="top"]    { --cd-bcb-color: #111111; }
.cd-bcb .ctrl-btn[data-face="bottom"] { --cd-bcb-color: #999; border-color: #999; }

.cd-bcb .auto-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  font-size: 11px;
  letter-spacing: 2px;
  color: rgba(0,0,0,0.45);
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  position: relative;
  z-index: 1;
}
.cd-bcb .toggle-track {
  width: 36px;
  height: 18px;
  background: rgba(0,0,0,0.15);
  border-radius: 9px;
  position: relative;
  transition: background 0.2s;
}
.cd-bcb .toggle-track.on { background: #111; }
.cd-bcb .toggle-thumb {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
}
.cd-bcb .toggle-track.on .toggle-thumb { transform: translateX(18px); }

@media (max-width: 720px) {
  .cd-bcb .scene { width: 260px; height: 260px; }
  .cd-bcb .cube { width: 220px; height: 220px; }
  .cd-bcb .face { width: 220px; height: 220px; padding: 18px; }
  .cd-bcb .face-front  { transform: translateZ(110px); }
  .cd-bcb .face-back   { transform: rotateY(180deg) translateZ(110px); }
  .cd-bcb .face-left   { transform: rotateY(-90deg) translateZ(110px); }
  .cd-bcb .face-right  { transform: rotateY(90deg) translateZ(110px); }
  .cd-bcb .face-top    { transform: rotateX(90deg) translateZ(110px); }
  .cd-bcb .face-bottom { transform: rotateX(-90deg) translateZ(110px); }
  .cd-bcb .face-label { font-size: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  .cd-bcb .cube { transition: none !important; }
}
(() => {
  const root = document.querySelector('.cd-bcb');
  if (!root) return;
  const cube = root.querySelector('[data-cd-bcb-cube]');
  const controls = root.querySelector('[data-cd-bcb-controls]');
  const toggle = root.querySelector('[data-cd-bcb-autotoggle]');
  const track = root.querySelector('[data-cd-bcb-autotrack]');
  if (!cube || !controls || !toggle || !track) return;

  const btns = controls.querySelectorAll('.ctrl-btn');
  let currentRx = -18, currentRy = 22;
  let autoRotate = false;
  let autoFrame = null;

  function setRotation(rx, ry) {
    currentRx = rx;
    currentRy = ry;
    cube.style.transform = `rotateX(${rx}deg) rotateY(${ry}deg)`;
  }

  btns.forEach(btn => {
    btn.addEventListener('click', () => {
      const rx = parseFloat(btn.dataset.rx);
      const ry = parseFloat(btn.dataset.ry);
      setRotation(rx, ry);
      btns.forEach(b => b.classList.remove('active'));
      btn.classList.add('active');
      if (autoRotate) stopAuto();
    });
  });

  function startAuto() {
    let start = null;
    const startRy = currentRy;
    function frame(ts) {
      if (!start) start = ts;
      const elapsed = ts - start;
      currentRy = startRy + elapsed * 0.04;
      cube.style.transform = `rotateX(${currentRx}deg) rotateY(${currentRy}deg)`;
      autoFrame = requestAnimationFrame(frame);
    }
    autoFrame = requestAnimationFrame(frame);
  }
  function stopAuto() {
    autoRotate = false;
    track.classList.remove('on');
    if (autoFrame) { cancelAnimationFrame(autoFrame); autoFrame = null; }
  }

  toggle.addEventListener('click', () => {
    autoRotate = !autoRotate;
    track.classList.toggle('on', autoRotate);
    if (autoRotate) startAuto();
    else stopAuto();
  });

  // Drag scoped to wrapper, not document
  let dragging = false, lastX = 0, lastY = 0;

  cube.addEventListener('mousedown', e => {
    dragging = true;
    cube.classList.add('dragging');
    lastX = e.clientX; lastY = e.clientY;
    if (autoRotate) stopAuto();
    e.preventDefault();
  });
  root.addEventListener('mousemove', e => {
    if (!dragging) return;
    currentRy += (e.clientX - lastX) * 0.5;
    currentRx -= (e.clientY - lastY) * 0.5;
    cube.style.transform = `rotateX(${currentRx}deg) rotateY(${currentRy}deg)`;
    lastX = e.clientX; lastY = e.clientY;
  });
  function endDrag() {
    dragging = false;
    cube.classList.remove('dragging');
  }
  root.addEventListener('mouseup', endDrag);
  root.addEventListener('mouseleave', endDrag);

  cube.addEventListener('touchstart', e => {
    dragging = true;
    lastX = e.touches[0].clientX;
    lastY = e.touches[0].clientY;
    if (autoRotate) stopAuto();
  }, { passive: true });
  root.addEventListener('touchmove', e => {
    if (!dragging) return;
    const t = e.touches[0];
    currentRy += (t.clientX - lastX) * 0.5;
    currentRx -= (t.clientY - lastY) * 0.5;
    cube.style.transform = `rotateX(${currentRx}deg) rotateY(${currentRy}deg)`;
    lastX = t.clientX;
    lastY = t.clientY;
  }, { passive: true });
  root.addEventListener('touchend', endDrag);
})();

Search CodeFronts

Loading…