CKTIS / CSS
offset-rotate — orijentacija na putanji
Svojstvo offset-rotate upravlja rotacijom elementa na putanji: element može pratiti njezin smjer, biti okrenut u suprotnom smjeru ili upotrebljavati fiksni kut.
Verzija: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Sintaksa
offset-rotate: [ auto | reverse ] || <angle>;offset-rotate upravlja rotacijom elementa na offset-path. offset-distance određuje njegov položaj; samo ovo svojstvo ne pokreće animaciju. Početna je vrijednost auto; svojstvo se ne nasljeđuje.
auto poravnava pozitivnu os X elementa sa smjerom putanje u trenutačnoj točki. reverse dodaje 180deg. Neobavezni <angle> dodaje daljnju rotaciju; samo kut, primjerice 0deg, isključuje poravnanje sa smjerom putanje. Operator || dopušta jednu ili obje komponente, bilo kojim redoslijedom.
Uz offset-path: none rotacija nema učinka. U primjeru okomita putanja vodi prema dolje, pa auto usmjerava strelicu prema dolje.
Primjeri
<!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>Rezultat
auto: ↓ reverse: ↑ 0deg: → auto 90deg: ←
Prikazani kôd i navedeni rezultat provjereni su u izoliranom okruženju metodom zabilježenom u dokazu provjere za ovu točnu verziju.