css - 使 CSS 更多 SCSS 以避免重复

标签 css sass

是否可以使以下 CSS 样式更像 SCSS 并避免为每个标题标签重复 b:after?

h1 b:after {
    height: 0.7rem;
    bottom: 1.0rem;
}

h2 b:after {
    height: 0.6rem;
    bottom: 0.6rem;
}

h3 b:after,
h4 b:after {
    height: 0.3rem;
    bottom: 0;
}

谢谢!

最佳答案

一种可以缩短代码并提供一些可重用性的方法是使用 mixin:

@mixin someMixin($height, $bottom) {
  & b:after {
    height: $height;
    bottom: $bottom;
  }
}

h1     { @include someMixin(0.7rem, 1.0rem); }
h2     { @include someMixin(0.6rem, 0.6rem); }
h3, h4 { @include someMixin(0.3rem, 0); }

关于css - 使 CSS 更多 SCSS 以避免重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48309015/

相关文章:

css - 更改 Sublime Text 3 中的默认 HTML 标签

html - CSS - 多个 div 的相同类和先前设置的不同颜色

css - 如何将以下 LESS 转换为 SCSS

css - :after node is not visible with text overflow ellipsis

css - Angular scss 不适用于 ngx-datatable

css - 终极 CSS 渐变代码破解 CSS

html - 仅使用 css 在图像下自动调整文本

html - 在 li-style-element 上添加额外的空间

ruby - 尝试访问 compass-core-1.0.0.alpha.16/stylesheets/.listen_test 时,compass watch 命令出错

css - 为什么我会收到语法错误 : SassError: expected "{"?