CKTIS / CSS
hypot() — magnitud de vector CSS
`hypot()` devuelve la magnitud de un vector formado por uno o más cálculos de tipo coherente.
Versión: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Sintaxis
hypot( <calc-sum># )hypot() devuelve la magnitud de un vector formado por uno o más cálculos de tipo coherente.
hypot(30px, 40px) fija la anchura en 50px; hypot(30%, 40%) da 100px en un contenedor de 200 px; hypot(-12px) con un argumento da el valor absoluto 12px. El incoherente hypot(10px, 1deg) devuelve false.
Gramática: hypot( <calc-sum># ).
El resultado corresponde a sqrt(A² + …) y conserva el tipo común de los argumentos: números, dimensiones compatibles o porcentajes. No se puede mezclar una longitud con un ángulo. Como acepta dimensiones directamente, sirve para diagonales y distancias de transformación; un argumento actúa como valor absoluto y cualquier argumento infinito produce infinity positivo.
Ejemplos
const host=document.createElement('div');host.style.cssText='width:200px;font-size:10px';document.body.append(host);
const used=value=>{const box=document.createElement('div');box.style.width=value;host.append(box);return getComputedStyle(box).width};
const triangle=used('hypot(30px, 40px)');
const percentage=used('hypot(30%, 40%)');
const absolute=used('hypot(-12px)');
const inconsistent=CSS.supports('width','hypot(10px, 1deg)');
console.log('triangle='+triangle+'; percentage='+percentage+'; single-negative='+absolute+'; inconsistent-types='+inconsistent);Resultado
triangle=50px; percentage=100px; single-negative=12px; inconsistent-types=false
`hypot()` devuelve la magnitud de un vector formado por uno o más cálculos de tipo coherente.