如何移除重复的样式?

huangapple go评论75阅读模式
英文:

boostrap theming -- How to remove duplicate styles?

问题

这个问题不太是一个代码问题,更像是一个最佳实践问题。我正在开发一个基于 https://github.com/HackerThemes/theme-kit 的自定义 Bootstrap 主题。我有一个我喜欢的工作主题,但我正在覆盖原始的 Bootstrap 主题中的一些样式。即使在压缩的 CSS 中,这些样式也会重复。例如,Bootstrap 定义了...

.btn-danger:hover {
    color: #fff;
    background-color: #ae130b;
    border-color: #a2120a;
}

...但我的代码也定义了...

.btn-danger:hover {
    border-color: #0000;
}

在最终的样式表中,这两种样式都存在。第二个样式覆盖了 Bootstrap,看起来一切都很好。但这会导致无用的代码。首先,是否有一种后处理器,我可以在 Gulp 中使用来消除这些重复并合并它们?其次,我应该只 fork Bootstrap 存储库并直接修改原始 SCSS 吗?

英文:

This question is less of a code question and more of a best-practices question. I am working on a custom bootstrap theme based on https://github.com/HackerThemes/theme-kit. I have a working theme that I like, however, I am overriding some styles in the original Bootstrap theme. Even in the minified CSS, these are duplicated. For example, Bootstrap defines...

.btn-danger:hover {
    color: #fff;
    background-color: #ae130b;
    border-color: #a2120a;
}

...but my code also defines...

.btn-danger:hover {
    border-color: #0000;
}

In the final stylesheet, both of these styles are present. The second style overrides Bootstrap and it looks just fine. However, this leads to useless code. First of all, is there a postprocessor of some sort that I can use with Gulp to eliminate these duplicates and consolidate them? Second, should I just fork the Bootstrap repository and modify the original SCSS directly?

答案1

得分: 1

It depends on what you @import. Looking at mytheme.scss, the entire Bootstrap SASS is imported, creating full duplicate code in the final CSS.

Instead you can pick specific SASS files to import and look at the option variables which also affect what CSS is generated. For example, setting $enable-grid-classes: false will prevent duplication of the entire grid system in the generated CSS.

英文:

It depends on what you @import. Looking at mytheme.scss, the entire Bootstrap SASS is imported, creating full duplicate code in the final CSS.

Instead you can pick specific SASS files to import and look at the option variables which also effects what CSS is generated. For example, setting $enable-grid-classes: false will prevent duplication of the entire grid system in the generated CSS.

huangapple
  • 本文由 发表于 2020年1月3日 23:40:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/59581358.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定