DEV Community

Jennifer Fadriquela
Jennifer Fadriquela

Posted on

2 2

CSS Custom Properties

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);
}
Enter fullscreen mode Exit fullscreen mode

razor

@{
  var labelText = "Some Label";
  var labelColor = "blue";
}
<div class="wrapper" style="--label-color: @labelColor; --label-text: '@labelText'">
  Hello
</div>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay