How to dynamically change css values (like color in whole app) etc

后端 未结 4 1931
孤独总比滥情好
孤独总比滥情好 2021-02-12 15:39

I have one question...

If you want conditional styling: you must use ng-class or ng-style construction.

But...

For example: I\'

4条回答
  •  有刺的猬
    2021-02-12 16:16

    The best way is generate a file like color.css with all css rules with color, background-color, border-color etc. overridden. But angularjs will not be enough.

    color-default.css

    body {
        background: #fff;
    }
    

    color.css

    body {
        background: #f00;
    }
    

    Full JS way
    Add class on every element you want to override. Create class for every properties like so:

    .skin-color { color: {{color}}; }
    .skin-background-color { background-color: {{color}}; }
    .skin-border-color { border-color: {{color}}; }
    etc..
    

    Apply class on your html where you want:

    My title

    Hello I'm online!

    No difference!

    I'm link

    You can save the color variable in localStorage for example.
    Démo: http://codepen.io/anon/pen/jPrabY

提交回复
热议问题