【问题标题】:Add media queries to Bootstrap 4 spacing generator将媒体查询添加到 Bootstrap 4 间距生成器
【发布时间】:2018-07-10 13:49:16
【问题描述】:

我正在开发一个 Bootstrap 3 项目,并从新的 Bootstrap 4 中提取了一些代码,以便拥有 my-1pb-5 等类。它适用于大屏幕。但是当我使用小屏幕设备查看页面时,边距和填充太大了。有什么办法可以解决这个问题?

这是生成这些类的代码 (_spacing.scss):

@each $breakpoint in map-keys($grid-breakpoints) {
  @include media-breakpoint-up($breakpoint) {
    $infix: breakpoint-infix($breakpoint, $grid-breakpoints);

    @each $prop, $abbrev in (margin: m, padding: p) {
      @each $size, $length in $spacers {

        .#{$abbrev}#{$infix}-#{$size} { #{$prop}: $length !important; }
        .#{$abbrev}t#{$infix}-#{$size},
        .#{$abbrev}y#{$infix}-#{$size} {
          #{$prop}-top: $length !important;
        }
        .#{$abbrev}r#{$infix}-#{$size},
        .#{$abbrev}x#{$infix}-#{$size} {
          #{$prop}-right: $length !important;
        }
        .#{$abbrev}b#{$infix}-#{$size},
        .#{$abbrev}y#{$infix}-#{$size} {
          #{$prop}-bottom: $length !important;
        }
        .#{$abbrev}l#{$infix}-#{$size},
        .#{$abbrev}x#{$infix}-#{$size} {
          #{$prop}-left: $length !important;
        }
      }
    }

    // Some special margin utils
    .m#{$infix}-auto { margin: auto !important; }
    .mt#{$infix}-auto,
    .my#{$infix}-auto {
      margin-top: auto !important;
    }
    .mr#{$infix}-auto,
    .mx#{$infix}-auto {
      margin-right: auto !important;
    }
    .mb#{$infix}-auto,
    .my#{$infix}-auto {
      margin-bottom: auto !important;
    }
    .ml#{$infix}-auto,
    .mx#{$infix}-auto {
      margin-left: auto !important;
    }
  }
}

【问题讨论】:

    标签: css twitter-bootstrap sass media-queries bootstrap-4


    【解决方案1】:

    正如您在 SASS 代码中看到的那样,该函数接受一个断点,该断点用于构造 infix 以生成响应式边距/填充类...

    m-sm-*m-md-*m-lg-* 等...

    当然,Bootstrap 3 不会以同样的方式使用它,因为它没有 $grid-breakpoints 数组/映射。您需要“解除”更多代码,或者完全切换到 Bootstrap 4。

    【讨论】:

    • 哦,很好,我没有注意到中缀的东西。非常感谢。
    猜你喜欢
    • 2019-09-09
    • 2015-12-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-26
    • 1970-01-01
    • 1970-01-01
    • 2013-09-18
    • 2013-12-28
    相关资源
    最近更新 更多