Is the CSS3 transform translate percentage values relative to its width and/or height?

12,540

In this section http://www.w3.org/TR/css3-transforms/#transform-property it states:

Percentages: refer to the size of bounding box

The definition of bounding box is (source)

A bounding box is the object bounding box for all SVG elements without an associated CSS layout box and the border box for all other elements. The bounding box of a table is the border box of its table wrapper box, not its table box.

And border box is (source)

The width and height properties include the padding and border, but not the margin. Note that padding and border will be inside of the box e.g. .box {width: 350px; border: 10px solid black;} lead to a box rendered in the browser of width: 350px.

I hope this helps

Share:
12,540
nonopolarity
Author by

nonopolarity

I started with Apple Basic and 6502 machine code and Assembly, then went onto Fortran, Pascal, C, Lisp (Scheme), microcode, Perl, Java, JavaScript, Python, Ruby, PHP, and Objective-C. Originally, I was going to go with an Atari... but it was a big expense for my family... and after months of me nagging, my dad agreed to buy an Apple ][. At that time, the Pineapple was also available. The few months in childhood seem to last forever. A few months nowadays seem to pass like days. Those days, a computer had 16kb or 48kb of RAM. Today, the computer has 16GB. So it is in fact a million times. If you know what D5 AA 96 means, we belong to the same era.

Updated on June 04, 2022

Comments

  • nonopolarity
    nonopolarity almost 2 years

    I think it is true that when we do a CSS3 transform translate using a percentage value, then that percentage is relative to its own width or height, so (50%, 75%) means 50% of its own width, 75% of its own height, but I can't find any specs that say that.

    Example: https://jsfiddle.net/cstsyw3s/1/
    using:

    transform: translate(100%, 100%)
    

    I looked into http://www.w3.org/TR/css3-transforms but can't find it mentioned there -- I could only find such as for transform-origin, the "percentages: refer to the size of bounding box", and I think the bounding box probably is rectangle with the element's width and height. (not including any border)... but I can't find a definition for bounding box except for SVG and table either.

  • nonopolarity
    nonopolarity over 8 years
    I see... so it for spec'ed for transform, not translate... for the line "A bounding box is the object bounding box for all SVG elements without an associated CSS layout box and the border box for all other elements", I read it as... "A bounding box is the object bounding box for all SVG elements without (an associated CSS layout box and the border box for all other elements)"... no wonder I didn't know what it meant at the end... I just thought it was talking about SVG elements
  • cocoa
    cocoa over 8 years
    is this what you were looking for?
  • manafi
    manafi over 5 years
    To be exceedingly clear: transform percentages are based on the size of the transformed element's own bounding box, not the size of the bounding box that contains the transformed element. It's based on its own size, unlike width, height, margins, etc.