Billys Gtr Billys Gtr - 2 months ago 20
CSS Question

CSS transform property with calc

I want to make a calculation for the transform property.
Is it possible to use the calc feature for that?

Something like:

width: calc(100vw-2vw);


but for transform

transform: translate(calc(100vw-2vw));


(Of course the above is not functional)

Answer

It works if you respect a white space in between calc values and signed used : transform: translate(calc(100vw - 2vw));

div {
  border:solid;
  float:right;
  height:20vw;
  width:20vw;
  transform:translate( calc(-100vw + 25vw) );
}
<div><p>Do not forget !<br/>use prefix if needed !!!</p><p>BTW, i float right</p></div>