Jennifer Fadriquela
Posted on May 29, 2021
I've been working on a Razor project and was finding a way to dynamically assign style values to ::before
elements. Best way to do this is via CSS Custom Properties
Here's what I came up with Razor code:
css
.wrapper::before {
background-color: var(--label-color);
content: var(--label-text);
}
razor
@{
var labelText = "Some Label";
var labelColor = "blue";
}
<div class="wrapper" style="--label-color: @labelColor; --label-text: '@labelText'">
Hello
</div>
💖 💪 🙅 🚩
Jennifer Fadriquela
Posted on May 29, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
css CSS Is Not Hard(You 're Just Missing These Basics)- Mastering the Foundation(Part 2)
November 29, 2024