简体   繁体   English

在多个scss样式表上使用sass mixins为页面设置颜色主题

[英]Setup color themes for Pages using sass mixins on multiple scss stylesheets

We're building a website where every menu item is basically a different section of the company - each section has its own color CI. 我们正在建立一个网站,每个菜单项基本上都是公司的不同部分-每个部分都有自己的颜色CI。 what I'm trying to do is setup a " color theme" that is easy to use and flesh out and obviously maintain. 我想做的是设置一个易于使用,充实并明显维护的“颜色主题”。 Im using sass mixins to create the initial setup with the include but this means that all my code for styling the website needs to go inside the mixin. 我使用sass mixins来创建包含的初始设置,但这意味着我所有用于样式化网站的代码都必须放在mixin中。 Not sure but I feel there must be a better, cleaner more maintainable method of doing this. 不确定,但我认为必须有一种更好,更清洁,更可维护的方法来执行此操作。 Below is how I have currently set up everything. 以下是我目前如何设置所有内容。

@mixin theme($name, $color) {

.#{$name} {
  h1 {
   color: $color;
  }
  .tda-nav__main {
   border-bottom: 5px solid $color;
  }
 }
}

@include theme(tda-gold,   $domain1);
@include theme(tda-blue,   $domain2);
@include theme(tda-gray,   $domain3);
@include theme(tda-green,  $domain4);
@include theme(tda-orange, $domain5);
@include theme(tda-yellow, $domain6);

the challenge im facing is that i do not have one sass stylesheet. 我面临的挑战是我没有一个无礼的样式表。 the project is broken up into multiple components for maintainablity as per ITCSS method. 根据ITCSS方法,该项目分为多个部分进行维护。 If I use the above method it means ill have to do a mixin on every single components stylesheet? 如果我使用上述方法,则意味着必须在每个单个组件样式表上进行一次混合吗? Feels to me there must be a better solution to do this. 我觉得必须有一个更好的解决方案来做到这一点。

my file structure wuld be something like: 我的文件结构如下所示:

|- scss |-scss

  • _settings.colors.scss _settings.colors.scss

  • _settings.mixins.scss _settings.mixins.scss

  • _components.layout.scss _components.layout.scss
  • _components.headlines.scss _components.headlines.scss
  • _components.buttons.scss _components.buttons.scss
  • ...etc ...等等
  • main.scss main.scss

Well after thinking it through we came up with this solution: 在仔细考虑之后,我们提出了以下解决方案:

@import "settings.variables";
@import "settings.mixins";
@import "settings.page";
@import "settings.text";
@import "components.layout";

@mixin theme($name, $color) {

 .#{$name} {

   @import "colored-elements"

 }
}

@include theme(tda-gold,   $domain1);
@include theme(tda-blue,   $domain2);
@include theme(tda-gray,   $domain3);
@include theme(tda-green,  $domain4);
@include theme(tda-orange, $domain5);
@include theme(tda-yellow, $domain6);

In this manner we only work on the color-components files where we define a single color which is set in the variables sass file and the call it over the whole project via the includes. 以这种方式,我们仅在颜色组件文件上工作,在文件中我们定义了在变量sass文件中设置的单一颜色,并通过include在整个项目中调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM