Znalostní bázeCentrum zkoušek
CSČeština
Vybrat jazyk13

CKTIS / CSS

offset-rotate — orientace na cestě

Vlastnost offset-rotate řídí otočení prvku na cestě: prvek může sledovat její směr, mířit opačným směrem nebo používat pevný úhel.

Verze: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntaxe

offset-rotate: [ auto | reverse ] || <angle>;

offset-rotate řídí otočení prvku na offset-path. offset-distance určuje jeho polohu; tato vlastnost sama o sobě animaci nespouští. Výchozí hodnota je auto; vlastnost se nedědí.

auto zarovná kladnou osu X prvku se směrem cesty v aktuálním bodě. reverse přidá 180deg. Volitelný <angle> přidá další otočení; samotný úhel, například 0deg, vypne zarovnání podle směru cesty. Operátor || dovoluje uvést jednu složku nebo obě, v libovolném pořadí.

Při offset-path: none nemá otočení žádný účinek. V příkladu vede svislá cesta dolů, takže auto nasměruje šipku dolů.

Příklady

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>offset-rotate on a vertical path</title>
<style>
  .examples { display: flex; flex-wrap: wrap; gap: 1rem; }
  figure { margin: 0; text-align: center; }
  .stage { position: relative; width: 110px; height: 100px; background: #eee; }
  .arrow {
    position: absolute;
    top: 0;
    left: 0;
    width: 40px;
    height: 20px;
    background: navy;
    clip-path: polygon(0 0, 60% 0, 100% 50%, 60% 100%, 0 100%);
    offset-path: path("M 55 15 L 55 85");
    offset-distance: 50%;
    offset-anchor: center;
  }
  .probe { position: absolute; top: 9px; width: 2px; height: 2px; }
  .tail { left: 5px; }
  .tip { left: 33px; }
</style>
</head>
<body>
<h1>Arrow orientation on a downward path</h1>
<div class="examples">
  <figure><div class="stage" aria-hidden="true"><div class="arrow" style="offset-rotate: auto"><span class="probe tail"></span><span class="probe tip"></span></div></div><figcaption><code>auto</code></figcaption></figure>
  <figure><div class="stage" aria-hidden="true"><div class="arrow" style="offset-rotate: reverse"><span class="probe tail"></span><span class="probe tip"></span></div></div><figcaption><code>reverse</code></figcaption></figure>
  <figure><div class="stage" aria-hidden="true"><div class="arrow" style="offset-rotate: 0deg"><span class="probe tail"></span><span class="probe tip"></span></div></div><figcaption><code>0deg</code></figcaption></figure>
  <figure><div class="stage" aria-hidden="true"><div class="arrow" style="offset-rotate: auto 90deg"><span class="probe tail"></span><span class="probe tip"></span></div></div><figcaption><code>auto 90deg</code></figcaption></figure>
</div>
<script>
  for (const figure of document.querySelectorAll('figure')) {
    const tail = figure.querySelector('.tail').getBoundingClientRect();
    const tip = figure.querySelector('.tip').getBoundingClientRect();
    const dx = (tip.left + tip.right) - (tail.left + tail.right);
    const dy = (tip.top + tip.bottom) - (tail.top + tail.bottom);
    const direction = dx === 0 && dy === 0 ? 'undetermined'
      : Math.abs(dx) > Math.abs(dy) ? (dx > 0 ? '→' : '←')
      : (dy > 0 ? '↓' : '↑');
    console.log(`${figure.querySelector('code').textContent}: ${direction}`);
  }
</script>
</body>
</html>

Výsledek

auto: ↓
reverse: ↑
0deg: →
auto 90deg: ←

Zobrazený kód a uvedený výsledek byly ověřeny v izolovaném prostředí metodou zaznamenanou v dokladu o ověření této přesné verze.

Zdroje