Home > database >  I want to give a dynamic width to CSS property's value in React. How can I achieve that
I want to give a dynamic width to CSS property's value in React. How can I achieve that

Time:12-09

const silderValue = averageRound * 20;

{silderValue}%

CodePudding user response:

you can do it in this way :

<div style={{width:`${silderValue}%`}}></div>

CodePudding user response:

import React from 'react';

function MyComponent() {
  // Calculate the width dynamically using JavaScript
  const width = 100;

  return (
    <div style={{ width: width }}>
      This element has a dynamic width.
    </div>
  );
}

  • Related