Translate % Relative To Own Box Width

Resolve a signed horizontal translate percentage against an explicitly supplied reference-box width in pixels; the caller chooses the transform reference box.

Description

A percentage translateX resolves against the width of the transform reference box.

A percentage translateX resolves against the width of the transform reference box. That differs from a background-position percentage, which uses the difference between the positioning area and the image size.1, 2

Resolve a signed horizontal translate percentage against an explicitly supplied reference-box width in pixels; the caller chooses the transform reference box.

When to use Translate % Relative To Own Box Width

Use this tool to resolve a signed horizontal translate percentage against an explicitly supplied reference-box width in pixels; the caller chooses the transform reference box.

Choose the CSS values, dimensions or counts for this calculation. Supply resolved numeric measurements in matching units and the explicit reference box or writing mode where required.

How to use Translate % Relative To Own Box Width and understand its results

  1. Choose the CSS values, dimensions or counts for this calculation. Supply resolved numeric measurements in matching units and the explicit reference box or writing mode where required.
  2. Enter referenceWidth, percent using the field table and calculation rules, then run the tool.
  3. Read translation. The explanation below defines the units, signs, ordering and any flags or placeholder values.
  4. If the tool reports an input issue, correct the values and run it again. Apply the stated assumptions when interpreting a successfully returned result.
Input fieldMeaningValue type; see rules belowRequirement
referenceWidthReference widthnumber; minimum: 0Required
percentPercentnumberRequired

Enter the explicitly chosen reference-box width in pixels and a signed percentage. The tool computes the horizontal pixel translation, normalizes negative zero to zero and tries a second multiplication order if a nonzero calculation underflows. A nonfinite or still-underflowed nonzero result is an input issue. Zero width or zero percent returns zero.

translation = referenceWidth × percent / 100

Units, indexing, boundary conditions and exceptional cases are defined in the calculation rules above.

Output fieldMeaningValue type
translationTranslationnumber
json
{
  "input": {
    "referenceWidth": 240,
    "percent": -25
  },
  "output": {
    "translation": -60
  }
}

Limitations and assumptions

The caller must determine the appropriate transform-box width. This does not inspect DOM geometry, resolve transform-origin or combine transforms, and it does not use the parent/container width automatically. Out-of-range percentages remain valid signed offsets.

Numeric inputs must be finite. Follow the calculation-specific rules for overflow, underflow and exceptional cases. Missing required fields, extra fields, wrong value types and violations of the calculation rules are input errors.

Alternative or Complementary methods

Use background-position Percent Alignment Formula: Resolve one background-position percentage as a pixel offset from the near edge using positioning-area size minus rendered-image size; oversized images and out-of-range percentages are allowed. For a complementary task, use Negative scale Flip Mirror Check: Classify axis reflections, orientation reversal, and collapsed axes of a two-dimensional CSS scale.

Further background: CSS Transforms: reference boxes and translation.

References

  1. Translate % Relative To Own Box Width — tool.io

  2. CSS Transforms: reference boxes and translation — W3C

Similar or alternative tools

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies