【问题标题】:Why my SASS project is disregarding media breakpoints?为什么我的 SASS 项目不考虑媒体断点?
【发布时间】:2021-06-27 11:54:15
【问题描述】:

我曾经在 React 项目中使用 CSS,但为了实现“暗模式”功能,我决定转向 SASS。

我也使用引导程序,所以我根据documentation 组织我的文件。

/* App.scss */

@import "~bootstrap/scss/bootstrap.scss";
@import './styles/_themes';
@import './styles/_fonts';


h1, h2, h3, h4, h5, h6 {
  font-family: $font-family-secondary;
  @include themed() {
    color: t($title-color)
  }
} 

p {
  font-family: $font-family-primary;

  @include themed() {
    color: t($text-color)
  }
}

hr, .nav-tabs {
  @include themed() {
    border-color: t($text-secondary-color)
  }
}

.base {
  height: 100%;
  width: 100%;
  
  @include themed() {
    background-color: t($background-color)
  }
}

.main {
  width: 750px;

  @include themed() {
    background-color: t($background-color)
  }
}

首先,我认为这是一个引导问题,但我自己的文件中也忽略了断点。

/* Footer.scss */

@media (max-width: 767px){
    #footer h5 {
        padding-left: 0;
        border-left: transparent;
        padding-bottom: 0px;
        margin-bottom: 10px;
   }
}

我做了一个最小的可重现示例并将其发布到代码沙箱:https://codesandbox.io/s/immutable-fire-qu9oe

请尝试减小屏幕尺寸并检查被忽略的媒体断点。

我做错了什么?

非常感谢!

编辑:

感谢robertp's answer 我可以修复我的自定义媒体断点。

但是如何修复引导程序?

例如,在我的navbar 中,我有一个引导类的媒体断点:

/* Navbar.scss */

@media (max-width: 571px) {
  .collapsing {
    @include themed() {
      position: absolute !important;
      z-index: 3;
      width: 100%;
      top: 75px;
    }
  }

  .collapse.show {
    @include themed() {
      display: block;
      position: absolute;
      z-index: 3;
      width: 100%;
      top: 75px;
    }
  }

  .navbar.open {
    @include themed() {
      transform: translate(0, 0)
    }
  }

  .overlay.open {
    @include themed() {
      height: 100%;
      opacity: 1;
    }
  }

}

但它没有用。另外,如何修复所有引导网格系统类?

编辑 2:

问题在于导入顺序。如果我将引导导入放在文件末尾,一切都会按预期工作!

【问题讨论】:

    标签: reactjs twitter-bootstrap sass


    【解决方案1】:

    这似乎是由于主题的特殊性。您的页脚 H5 元素根据主题设置样式,因此您需要覆盖它的主题版本。

    覆盖基于媒体查询的样式的主题样式的屏幕截图:

    这应该可行:

    @media (max-width: 767px){
      #footer h5 {
        @include themed() {
          padding-left: 0;
          border-left: transparent;
          padding-bottom: 0px;
          margin-bottom: 10px;
        }
      }
    }
    

    【讨论】:

    • 感谢您的回复!这确实修复了我的自定义媒体断点,但我该如何修复引导程序断点?
    • 查看您的演示,不清楚您要在 Bootstrap 中修复什么。我在您的代码中看不到更多断点,并且主题似乎对我有用(当我在 TR 中点击太阳图标时,站点颜色会发生变化)。您能否具体说明您遇到的 Bootstrap 特定问题以及相关代码在哪里?
    • 如果您检查沙箱,您可以看到当我们减小屏幕宽度时列没有调整大小。对于较大的设备,预计每行有两列,对于较小的设备,一列。如果您减小屏幕宽度,您将始终看到每行有两列。相关代码可能与自定义引导程序的类有关,但您可以在Home.js 文件(沙箱中的 src/componentes/common)上看到 react 实现。
    • 我编辑了问题以提供更多详细信息。再次感谢!
    • 请查看我的更新答案,其中包含有关如何在不同断点上调整网格中列大小的信息。
    猜你喜欢
    • 1970-01-01
    • 2014-03-10
    • 2019-08-20
    • 2018-05-14
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多