I am having troubles to transfer my calculated php variable (which gives an output form -90 –> 90) to my css bar class (for a gauge). All the code is defined in the same php file
I want to do it with te following :
.bar { position: absolute; width: 50%; height: 100%; background-color: var(--black); transform: rotate(<?php echo $degree; ?>deg)>;
Tis is inside the style element. The value of degree is calculated below the style element inside a p element.
Could anybody help me
2
Answers
You can generate a separate stylesheet with the dynamic value and then include it in your HTML.
style.php
Then you need to include this stylesheet using the link element, like this.
If you truly are "calculating it below", then CSS custom properties still work perfectly with this, you just use the value in your style, optionally with a default value, and then set the custom property value in the
style
attribute on the tag itself:CodePen demo: https://codepen.io/cjhaas/pen/rNrgQoK