Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • tungdo 2 posts 71 karma points
    Dec 09, 2017 @ 03:44
    tungdo
    0

    Changing CSS variables in a property

    Hi everyone,

    I would like to change the colors of my scheme using a property. I have the property defined (which works), but how can I call this property in the CSS file? Everything I tried didn't work. Or is there any other way to achieve this?

  • Mikael Axel Kleinwort 67 posts 310 karma points c-trib
    May 21, 2020 @ 13:42
    Mikael Axel Kleinwort
    0

    Hello @tungdo,

    it is not possible to reference C# data in a css file.

    What you can do is to use your Umbraco doc type property to specify a class name which then is added to an html element in your view file.

    So when your css files looks like this:

    .colorSchemeLight {
        color: black;
        background-color: white;
    }
    
    .colorSchemeDark {
        color: white;
        background-color: black;
    }
    

    and your doc type property of type string is called myCssClassNameProperty, you can reference this in your .cshtml like

    <div class="@Model.myCssClassNameProperty">
    

    If you use a Radio button list as your property editor, then you can predefine the available values so only valid class names can be chosen.

    Hope this helps!

Please Sign in or register to post replies

Write your reply to:

Draft