I want to randomly set the background color of each element
But when I insert it into the following code, the background color becomes transparent:
{ modules.map((module, index) => ( <div className='carousel-module shadow' style={{ background: "#" + Math.floor(Math.random()*16777215).toString(16)}} > <p className='module-element-text'>{module.name ? module.name : "N/A"}</p> <p className='module-element-text'>{module.code ? module.code : "N/A"}</p> <Button onClick={() => setShow(false)} variant="success" className='modules-list-button'> Load </Button> </div> )) }
Would be great to hear your suggestions on how to make it work.
This is the function I use to generate hex colors. Your method might introduce an alpha channel into the color, making it transparent.