Change Theme / CSS based on user

前端 未结 8 1928
说谎
说谎 2021-01-02 06:10

I am building a product that we are eventually going to white-label. Right now I am trying to figure out the best way to facilitate these requirements programmatically so th

8条回答
  •  醉话见心
    2021-01-02 06:41

    If I understood correctly, you want to facilitate color and typography related changes. What about layout? If we safely assume that only color and typography are going to change, we can reuse the same style classes at the end of existing base CSS file and thus override the styles (using !important though a good idea, prevents users from overriding with their custom styles).

    These newly created classes can be compressed to a single line string and stored as a varchar, which would then be linked/copied inline while building the page. I can think of the following options

    1. Inline CSS
    2. Create a file partition where you can dump the generated CSS files and let browsers refer to that location (by creating a softlink?)
    3. Use Ajax, retrieve the CSS and modify the DOM

    If layout is going to change, we are in a thicker soup, I would avoid this as the complexities involved with scripting/event-handling are way too much.

提交回复
热议问题