Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在开发一个网站,我希望允许用户切换主题(主要是颜色、字体等,而不是布局)。
我的想法是在 body 上有一个类,比如 theme1,然后将所有样式放在该类下:
.theme1{ //less code here } .theme2{ //less code here }
这样,为了切换主题,我所要做的就是替换 body 上的类。
这是一个很好的解决方案,有没有更好的方法?
如果您使用的是 LESS,那么将所有样式包装在一个
body.theme-class { }
选择器。
这似乎是合理的;它使更改主题成为更改 body 标签上的类的简单案例。