for (let i = 0; i < divCount.length; i++) {
var radio = divCount[i].getElementsByClassName("radio_count");
for (var index = 0; index < radio.length; index++) {
var element: any = radio[index];
console.log(element);
var style ="width:calc(100% / " + element + ")";
element.style = style;
}
}
Using the calc() function in inline styles in React # Set the style prop on the element. Pass the result of calling calc() as the value for a CSS property. The call to calc() should be wrapped in a string, e.g. 'calc(100% - 600px)' .
The width of an inline element is the width of the content. The height and width of an inline element cannot be set in CSS. You cannot set the height and width of block-level elements in CSS.
Template literals should help.
<div style={{width: `calc(100% / ${yourVariable})`}}></div>
Example https://jsfiddle.net/69z2wepo/81579/
What @Andrew wrote is correct, however here's a non ES2015/ES6 version (the question did not specify):
In the react component render, you can use the following JSX:
render: function() {
var dynamicWidth = 'calc(100% / ' + value + ')';
return (
<div>
<div style={{width: dynamicWidth}}></div>
</div>
);
Basically how this works is on each render that string gets interpolated. What @Andrew has shown you is just a better syntax available to do the same thing in ES6
calc(100% / ${value})
is conceptually equivalent to 'calc(100% / ' + value + ')'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With