scss 自定义SASS Bootstrap Column Sizes.scss

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了scss 自定义SASS Bootstrap Column Sizes.scss相关的知识,希望对你有一定的参考价值。

// ++++++++++++++++ HOW TO USE ++++++++++++++++
Copy the included mixins and functions into _mixins.scss
Say we want to have a custom grid size that applies at $screen-sm-min
In _grid.scss find @media (min-width: $screen-sm-min) and add the following to the end
  // Custom Sizes
  @include calc-grid(8.5, sm, width);
  @include calc-grid(3.5, sm, width);
  @include make-grid-columns-float-custom(sm, "8r5");
  @include make-grid-columns-float-custom(sm, "3r5");
  
This gives us a custom column size of 8.5 and 3.5
Notice the 8r5 and 3r5 in make-grid-columns-float-custom
  If we had used 8.5 and 3.5 instead the class name would become .col-sm-8.5 which would represent an element
  that contains both the class col-sm-8 and the seperate class 5.
  To avoid this I went with the aforementioned format.
If you want a custom offset of 0.5 then you'd also add:
  @include calc-grid(0.5, sm, offset);
// -----------------------------------------------------
// _mixins.scss
@mixin make-grid-columns-float-custom($class, $index) {
  $classname: ".col-" + $class + "-" + $index;
  #{$classname} {
    float: left;
  }
}

@function rmod($val1) {
  $frac: $val1 - floor($val1); // discard int
  $return: 0;
  $tmp: 0;
  // End result will be 0.0
  @while $frac > 0 {
    $frac: $frac * 10;
    @if $frac > 1 {
      /* During the final loop $frac will end with .0
         but reports 0.0 == 0.0 as false with this functions
         sequence of events (normally 0.0 == 0.0 returns
         true). The following @if statement is a workaround
         and 0.0 < 0 returns true which correctly terminates
         the loop. */
      @if $frac - $frac*10 < 5 {
        $tmp: round($frac);
      } @else {
        $tmp: floor($frac);
      }
    } @else {
      $tmp: 0;
    }
    $return: $return * 10;
    @if $tmp != 0 {
      $return: $return + $tmp;
      $frac: $frac - $tmp;
    }
  }
  @return $return;
}

@mixin calc-grid($index, $class, $type) {
  @if ($type == width) and ($index > 0) {
    $index_classname: $index;
    @if (floor($index) != $index) {
      $index_classname: floor($index) + "r" + rmod($index);
    }
    .col-#{$class}-#{$index_classname} {
      width: percentage(($index / $grid-columns));
    }
  }
  @if ($type == push) {
    .col-#{$class}-push-#{$index} {
      left: percentage(($index / $grid-columns));
    }
  }
  @if ($type == pull) {
    .col-#{$class}-pull-#{$index} {
      right: percentage(($index / $grid-columns));
    }
  }
  @if ($type == offset) {
    $index_classname: $index;
    @if (floor($index) != $index) {
      $index_classname: floor($index) + "r" + rmod($index);
    }
    .col-#{$class}-offset-#{$index_classname} {
      margin-left: percentage(($index / $grid-columns));
    }
  }
}

以上是关于scss 自定义SASS Bootstrap Column Sizes.scss的主要内容,如果未能解决你的问题,请参考以下文章

scss 具有自定义变量和样式覆盖的Bootstrap-Sass项目导入结构。

通过 Bootstrap-Vue + Webpack + Vue.js 使用自定义 SCSS

如何在 Bootstrap 4 和 Sass 中设置自定义按钮文本颜色?

如何在 Angular 中使用带有 SASS 的 Bootstrap 4

使用 SASS 函数主题颜色级别在引导程序 4 中创建自定义渐变

如何将 SASS 文件添加到 bootstrap-vue/webpack(vue-cli 项目)?