RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 862694
Accepted
Daniil Dubchenko
Daniil Dubchenko
Asked:2020-08-01 01:38:03 +0000 UTC2020-08-01 01:38:03 +0000 UTC 2020-08-01 01:38:03 +0000 UTC

SCSS。如何使用@extend '.class' 但最终文件中没有'.class'

  • 772

我使用 scss 并通过 @import 连接引导程序,但为了不将引导类与 html 乱扔垃圾并坚持使用 bam,例如,我使用 @extend

.header {
   @extend .container;
...

但是所有引导类最终都在最终编译的 main.css 文件中。一般来说,问题是是否可以扩展引导类,但这样这些类本身就不会进入最终文件

我通过wiredep自动连接了凉亭依赖项

// bower:scss

@import "../../libs/bootstrap/scss/bootstrap.scss";
css
  • 2 2 个回答
  • 10 Views

2 个回答

  • Voted
  1. Best Answer
    Daniil Dubchenko
    2020-03-29T14:56:59Z2020-03-29T14:56:59Z

    花了不到一年的时间,达到了理想的解决方案。

    从库中提取所需的代码,并将其添加到带有 mixins 的单独文件中,用.class模板的创建替换类的创建%class。这里只有一个网格,因为 我不在引导程序中使用其余部分。现在最终的 css 文件中的代码干净了 1.5K 行

        %container {
            @include make-container();
    
            @include make-container-max-widths();
        }
    
        %container-fluid {
            @include make-container();
        }
    
        %row {
            @include make-row();
        }
    
    
        @mixin make-grid-columns($columns: $grid-columns, $gutter: $grid-gutter-width, $breakpoints: $grid-breakpoints) {
            // Common properties for all breakpoints
            %grid-column {
                position: relative;
                width: 100%;
                padding-right: $gutter / 2;
                padding-left: $gutter / 2;
            }
    
            @each $breakpoint in map-keys($breakpoints) {
                $infix: breakpoint-infix($breakpoint, $breakpoints);
    
                // Allow columns to stretch full width below their breakpoints
                @for $i from 1 through $columns {
                    %col#{$infix}-#{$i} {
                        @extend %grid-column;
                    }
                }
                %col#{$infix},
                %col#{$infix}-auto {
                    @extend %grid-column;
                }
    
                @include media-breakpoint-up($breakpoint, $breakpoints) {
                    // Provide basic `.col-{bp}` classes for equal-width flexbox columns
                    %col#{$infix} {
                        flex-basis: 0;
                        flex-grow: 1;
                        max-width: 100%;
                    }
                    %col#{$infix}-auto {
                        flex: 0 0 auto;
                        width: auto;
                        max-width: 100%; // Reset earlier grid tiers
                    }
    
                    @for $i from 1 through $columns {
                        %col#{$infix}-#{$i} {
                            @include make-col($i, $columns);
                        }
                    }
    
                    %order#{$infix}-first { order: -1; }
    
                    %order#{$infix}-last { order: $columns + 1; }
    
                    @for $i from 0 through $columns {
                        %order#{$infix}-#{$i} { order: $i; }
                    }
    
                    // `$columns - 1` because offsetting by the width of an entire row isn't possible
                    @for $i from 0 through ($columns - 1) {
                        @if not ($infix == "" and $i == 0) { // Avoid emitting useless .offset-0
                            %offset#{$infix}-#{$i} {
                                @include make-col-offset($i, $columns);
                            }
                        }
                    }
                }
            }
        }
    
        @include make-grid-columns();
    
        @each $breakpoint in map-keys($grid-breakpoints) {
            @include media-breakpoint-up($breakpoint) {
                $infix: breakpoint-infix($breakpoint, $grid-breakpoints);
    
                @each $value in $displays {
                    %d#{$infix}-#{$value} { display: $value !important; }
                }
            }
        }
    
    

    PS Onlyidea发誓这样的模板不存在,因为它们是动态创建的。没什么大不了,但我想我会指出来

    • 3
  2. E_K
    2020-08-01T02:15:18Z2020-08-01T02:15:18Z

    为您的类使用 sass mixins 或使用模板选择器和 mixins 对其进行样式设置,并通过@extend.

    引导 sass 混合

    • 2

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    是否可以在 C++ 中继承类 <---> 结构?

    • 2 个回答
  • Marko Smith

    这种神经网络架构适合文本分类吗?

    • 1 个回答
  • Marko Smith

    为什么分配的工作方式不同?

    • 3 个回答
  • Marko Smith

    控制台中的光标坐标

    • 1 个回答
  • Marko Smith

    如何在 C++ 中删除类的实例?

    • 4 个回答
  • Marko Smith

    点是否属于线段的问题

    • 2 个回答
  • Marko Smith

    json结构错误

    • 1 个回答
  • Marko Smith

    ServiceWorker 中的“获取”事件

    • 1 个回答
  • Marko Smith

    c ++控制台应用程序exe文件[重复]

    • 1 个回答
  • Marko Smith

    按多列从sql表中选择

    • 1 个回答
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Suvitruf - Andrei Apanasik 什么是空? 2020-08-21 01:48:09 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5