CKTIS / CSS
offset-rotate — orientácia na dráhe
Vlastnosť offset-rotate riadi otočenie prvku na dráhe: prvok môže sledovať jej smer, smerovať opačne alebo používať pevný uhol.
Verzia: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
offset-rotate: [ auto | reverse ] || <angle>;offset-rotate riadi otočenie prvku na offset-path. offset-distance určuje jeho polohu; táto vlastnosť sama osebe nespúšťa animáciu. Počiatočná hodnota je auto; vlastnosť sa nededí.
auto zarovná kladnú os X prvku so smerom dráhy v aktuálnom bode. reverse pridá 180deg. Voliteľný <angle> pridá ďalšie otočenie; samotný uhol, napríklad 0deg, vypne zarovnanie podľa smeru dráhy. Operátor || umožňuje uviesť jednu zložku alebo obe, v ľubovoľnom poradí.
Pri offset-path: none nemá otočenie žiadny účinok. V príklade vedie zvislá dráha nadol, takže auto nasmeruje šípku nadol.
Prí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ýsledok
auto: ↓ reverse: ↑ 0deg: → auto 90deg: ←
Zobrazený kód a uvedený výsledok boli overené v izolovanom prostredí metódou zaznamenanou v dôkaze o overení tejto presnej verzie.