transform-box
Quick Summary for transform-box
The transform-box CSS property defines the layout box to which the transform and transform-origin properties relate.
Code Usage for transform-box
/* Keyword values */ transform-box: content-box; transform-box: border-box; transform-box: fill-box; transform-box: stroke-box; transform-box: view-box;  /* Global values */ transform-box: inherit; transform-box: initial; transform-box: revert; transform-box: unset; 
More Details for transform-box

transform-box

The transform-box CSS property defines the layout box to which the transform and transform-origin properties relate.

/* Keyword values */ transform-box: content-box; transform-box: border-box; transform-box: fill-box; transform-box: stroke-box; transform-box: view-box;  /* Global values */ transform-box: inherit; transform-box: initial; transform-box: revert; transform-box: unset; 

Syntax

The transform-box property is specified as one of the keyword values listed below.

Values

content-box

The content box is used as the reference box. The reference box of a <table> is the border box of its table wrapper box, not its table box.

border-box

The border box is used as the reference box. The reference box of a <table> is the border box of its table wrapper box, not its table box.

fill-box

The object bounding box is used as the reference box.

stroke-box

The stroke bounding box is used as the reference box.

view-box

The nearest SVG viewport is used as the reference box. If a viewBox attribute is specified for the SVG viewport creating element, the reference box is positioned at the origin of the coordinate system established by the viewBox attribute, and the dimension of the reference box is set to the width and height values of the viewBox attribute.

Formal definition

Initial valueview-box
Applies totransformable elements
Inheritedno
Computed valueas specified
Animation typediscrete

Formal syntax

content-box | border-box | fill-box | stroke-box | view-box

Examples

SVG transform-origin scoping

In this example we have an SVG:

<svg id="svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50">   <g>     <circle id="center" fill="red" r="1" transform="translate(25 25)" />     <circle id="boxcenter" fill="blue" r=".5" transform="translate(15 15)" />     <rect id="box" x="10" y="10" width="10" height="10" rx="1" ry="1" stroke="black" fill="none" />   </g> </svg> 

In the CSS we have an animation that uses a transform to rotate the rectangle infinitely. transform-box: fill-box is used to make the transform-origin the center of the bounding box, so the rectangle spins in place. Without it, the transform origin is the center of the SVG canvas, and so you get a very different effect.

svg{   width:80vh;   border:1px solid #d9d9d9;   position:absolute;   margin: auto;   top: 0;   right: 0;   bottom: 0;   left: 0; }  #box{   transform-origin:50% 50%;   /*+++++++++++++++++++++++++++*/   /* if I remove this rule the pen won't work properly on Chrome for Mac, FF, Safari   Will still work properly on Chrome for PC & Opera*/   transform-box: fill-box;   /*Alternatively  I can use transform-origin:15px 15px;*/   /*+++++++++++++++++++++++++++*/   animation: rotateBox 3s linear infinite; }  @keyframes rotateBox {   to {     transform: rotate(360deg);   } 

Full credit for this example goes to Pogany; see this codepen for a live version.

Specifications

Specification
CSS Transforms Module Level 1 # transform-box

See also

Using CSS transforms transform, transform-origin

Last modified: Sep 12, 2021, by MDN contributors

Select your preferred language English (US)Français日本語中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote

"Olivia, my eldest daughter, caught measles when she was seven years old. As the illness took its usual course I can remember reading to her often in bed and not feeling particularly alarmed about it. Then one morning, when she was well on the road to recovery, I was sitting on her bed showing her how to fashion little animals out of coloured pipe-cleaners, and when it came to her turn to make one herself, I noticed that her fingers and her mind were not working together and she couldn’t do anything. 'Are you feeling all right?' I asked her. 'I feel all sleepy,' she said. In an hour, she was unconscious. In twelve hours she was dead. The measles had turned into a terrible thing called measles encephalitis and there was nothing the doctors could do to save her. That was...in 1962, but even now, if a child with measles happens to develop the same deadly reaction from measles as Olivia did, there would still be nothing the doctors could do to help her. On the other hand, there is today something that parents can do to make sure that this sort of tragedy does not happen to a child of theirs. They can insist that their child is immunised against measles. ...I dedicated two of my books to Olivia, the first was ‘James and the Giant Peach’. That was when she was still alive. The second was ‘The BFG’, dedicated to her memory after she had died from measles. You will see her name at the beginning of each of these books. And I know how happy she would be if only she could know that her death had helped to save a good deal of illness and death among other children."

I just checked google books for BFG, and the dedication is there. 

https://www.google.com.au/books/edition/_/quybcXrFhCIC?hl=en&gbpv=1 


Roald Dahl, 1986
Random CSS Property

will-change

The will-change CSS property hints to browsers how an element is expected to change. Browsers may set up optimizations before an element is actually changed. These kinds of optimizations can increase the responsiveness of a page by doing potentially expensive work before they are actually required.
will-change css reference