It is common knowledge that inline styles are considered bad practice and may not be compatible with certain security policies, such as the Content Security Policy.
The ideal goal is to achieve this without relying on inline styles:
<?php
$spacer_height = 390; // a dynamic value obtained from user input
?>
<div class="spacer" style="height:<?php echo $spacer_height; ?>"></div>
This is what is desired:
HTML:
<?php
$spacer_height = 390; // a dynamic value from user input
?>
<div class="spacer spacerheight-<?php echo $spacer_height; ?>" data-height="<?php echo $spacer_height; ?>"></div>
External Stylesheet:
.spacer {
height: spacer_height + "px"; // placeholder code for illustration
}
Is there a way to accomplish this using only CSS, without resorting to JavaScript or polyfills?
I came across a similar question from 5 years ago: CSS values using HTML5 data attribute
However, I am curious if there have been any advancements since then or if there exists a CSS-only solution that does not rely on attributes. Even a solution specifically tailored for handling integers would be helpful.
Edit: In case no alternative solution is available, a functional polyfill suggestion would also be appreciated.