<Parent style={{transform: "scale(2)"}}>
<Child_1 />
<Child_2 />
<Child_3 />
<Child_4 />
<Parent />
The goal is to have the Child_X to scale proportionally and the spacing between them to scale proportionally.
how can this be easily achieved?
You can use their widths if they are divs.
document.getElementById("parentElement").offsetWidth
Here, we are finding the width of the parent element.
document.getElementById("childElement").offsetWidth
Here, we are finding the width of the child element.
let parentWidth = document.getElementById("parentElement").offsetWidth;
let childWidth = document.getElementById("childElement").offsetWidth;
let proportion = childWidth / parentWidth;
Here, we are dividing the child elements width by the parent elements width so that we can get the proportion by which we have to size the element.
scale() property:let parentWidth = document.getElementById("parentElement").offsetWidth;
let childWidth = document.getElementById("childElement").offsetWidth;
let proportion = childWidth / parentWidth;
<Parent style={{transform: "scale(2)"}}>
<Child_1 style={{transform: {`scale(${2 * proportion})`}}}/>
<Child_2 style={{transform: {`scale(${2 * proportion})`}}}/>
<Child_3 style={{transform: {`scale(${2 * proportion})`}}}/>
<Child_4 style={{transform: {`scale(${2 * proportion})`}}}/>
<Parent />
And there you go, by using the proportion variable to dynamically change the value of the scale, you can easily achieve what you want!
Given, that this code works in theory I can't say that it will work for you since you haven't provided any code in your question. This is bad, and make sure you provide the code from now on. This is only for your own good so that we can write a better answer for your question.