CKTIS / CSS
offset-rotate — orientação num percurso
A propriedade offset-rotate controla a rotação de um elemento num percurso: pode seguir a direção do percurso, ficar orientado no sentido oposto ou usar um ângulo fixo.
Versão: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Sintaxe
offset-rotate: [ auto | reverse ] || <angle>;offset-rotate controla a rotação de um elemento num offset-path. offset-distance determina a sua posição; esta propriedade, por si só, não inicia uma animação. O valor inicial é auto; a propriedade não é herdada.
auto alinha o eixo X positivo do elemento com a direção do percurso no ponto atual. reverse adiciona 180deg. Um <angle> opcional acrescenta rotação; um ângulo isolado, como 0deg, desativa o alinhamento com a direção do percurso. O operador || permite indicar um dos componentes ou ambos, por qualquer ordem.
Com offset-path: none, a rotação não produz efeito. No exemplo, o percurso vertical segue para baixo, pelo que auto orienta a seta para baixo.
Exemplos
<!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>Resultado
auto: ↓ reverse: ↑ 0deg: → auto 90deg: ←
O código apresentado e o resultado declarado foram verificados num ambiente isolado pelo método registado na prova de verificação desta versão exata.