CKTIS / CSS
translate(): moving a box without moving its layout slot
Resolve percentages against the transform reference box and distinguish rendered position from layout and CSSOM matrices.
Version: CSS Modules
Syntax
transform-box: border-box; transform: translate(50%, 25%);translate(tx, ty) shifts the local coordinate system horizontally and vertically. Both arguments accept lengths or percentages; the second is optional and defaults to zero. Nonzero lengths need units. Horizontal percentages use the width of the transform reference box, vertical percentages its height, rather than the parent’s dimensions. transform-box chooses that reference, which matters when padding and borders differ from the content box.
A transform changes rendering without reallocating the element’s normal-flow slot or moving following siblings to make space. Function order matters: translate(10px,0) scale(2) and scale(2) translate(10px,0) produce different translations. This function in transform is distinct from the separate translate property and from the SVG transform attribute, whose syntax differs. A pure translation does not need a changed transform-origin.
The example has 80px by 40px content, 10px padding and a 5px border, giving a 110px by 70px border box. The 50% and 25% translation moves its rendered bounds by 55,17.5 with border-box and 40,10 with content-box. In this Chromium 157 run, the serialized computed matrix still reports 55,17.5 for content-box, despite the measured 40,10 movement. The example prints that discrepancy instead of treating CSSOM serialization as the final geometry.
The single argument produces 12,0. Reversing the translation and scale changes the matrix translation from 10,0 to 20,0, while the following sibling moves by zero and layout dimensions stay 110px by 70px. Use getBoundingClientRect() when you need the transformed viewport rectangle; keep its coordinates separate from layout measurements and from local matrix coordinates.
Examples
const host=document.createElement('div');host.style.cssText='position:fixed;left:100px;top:100px;width:400px';
const box=document.createElement('div');box.style.cssText='width:80px;height:40px;padding:10px;border:5px solid;transform-box:border-box';
const sibling=document.createElement('div');sibling.style.height='10px';host.append(box,sibling);document.body.append(host);
const before=sibling.getBoundingClientRect().top;
const matrix=()=>{const m=new DOMMatrix(getComputedStyle(box).transform);return [m.m41,m.m42].join(',')};
const position=()=>{const r=box.getBoundingClientRect();return [r.left-100,r.top-100].join(',')};
box.style.transform='translate(50%,25%)';const border=position();
box.style.transformBox='content-box';const content=position();const reported=matrix();
box.style.transform='translate(12px)';const single=matrix();
box.style.transform='translate(10px,0) scale(2)';const first=matrix();
box.style.transform='scale(2) translate(10px,0)';const second=matrix();
console.log('border='+border+'; content='+content+'; content-matrix='+reported+'; single='+single);
console.log('order='+first+' / '+second+'; sibling-shift='+(sibling.getBoundingClientRect().top-before)+'; layout='+box.offsetWidth+'x'+box.offsetHeight);
console.log('nonzero-unitless='+CSS.supports('transform','translate(12,0)'));
host.remove();Result
border=55,17.5; content=40,10; content-matrix=55,17.5; single=12,0 order=10,0 / 20,0; sibling-shift=0; layout=110x70 nonzero-unitless=false
The percentage comparison uses measured bounds relative to the fixed host. The content-box matrix discrepancy is explicitly limited to the tested Chromium 157; it is not the CSS definition of percentage translation.