Base de conhecimentoCentro de Exames
PT · PTPortuguês (Portugal)
Escolher idioma13

CKTIS / CSS

offset-position — posição inicial do percurso

Numa função de percurso que usa a posição inicial do movimento, como `ray()`, `offset-position` pode fornecer essa posição quando se omite o argumento opcional de posição. `inset()` não aceita esse argumento e determina o contorno do percurso a partir da caixa de referência.

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

Sintaxe

offset-position: normal | auto | <position>;

offset-position aplica-se a elementos transformáveis e não é herdada. O valor inicial é normal: não é fornecida qualquer posição inicial; nesse caso, ray() começa por predefinição no centro.

auto seleciona o canto superior esquerdo da caixa própria do elemento. Por outro lado, <position>, como left top ou 25% 50%, seleciona um ponto relativo ao bloco contentor. As percentagens usam as dimensões deste, sem subtrair o tamanho do elemento.

Um at <position> explícito em ray() tem prioridade. offset-distance define a distância ao longo do percurso; offset-anchor seleciona o ponto do elemento colocado nesse local. Com offset-path: none, não há transformação de offset.

Exemplos

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Setting a motion path starting position</title>
  <style>
    .stage { position: relative; width: 200px; height: 120px; background: #eee; }
    #dot {
      position: absolute;
      top: 0;
      left: 0;
      width: 10px;
      height: 10px;
      background: #064;
      offset-path: ray(90deg);
      offset-position: 25% 50%;
      offset-distance: 20px;
      offset-anchor: left top;
      offset-rotate: 0deg;
    }
  </style>
</head>
<body>
  <p>The ray omits an explicit starting position so that <code>offset-position</code> can supply one. This example checks syntax and computed style, not the ray's rendered origin.</p>
  <div class="stage" aria-hidden="true"><div id="dot"></div></div>
  <script>
    if (CSS.supports('offset-position', '25% 50%')) {
      const value = getComputedStyle(document.getElementById('dot')).getPropertyValue('offset-position');
      console.log(`offset-position syntax: supported; computed value: ${value}`);
    } else {
      console.log('offset-position syntax: unsupported');
    }
  </script>
</body>
</html>

Resultado

offset-position syntax: supported; computed value: 25% 50%

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.

Fontes