【问题标题】:Why aren't my media query variables working in Bootstrap?为什么我的媒体查询变量在 Bootstrap 中不起作用?
【发布时间】:2015-06-01 11:27:05
【问题描述】:

我目前是 Bootstrap (3.3.4) 的新手,我的启动站点的页脚位置似乎有问题。我只希望将页脚固定在更大的屏幕(平板电脑和电脑)上,而不是移动设备上。

由于 Bootstrap 现在是移动优先的,我没有在我的 CSS 中明确声明页脚的位置样式(因为我不想修复它),除了我的大屏幕媒体查询:

/* Extra small devices (phones, less than 768px) */
/* No media query since this is the default in Bootstrap */

/* Small devices (tablets, 768px and up) */
@media (min-width: @screen-sm-min) {
        
  /* Pull out the header and footer */
  .mastfoot {
    position: fixed;
    bottom: 0;
  }

}

/* Medium devices (desktops, 992px and up) */
@media (min-width: @screen-md-min) {
    
  /* Pull out the header and footer */
  .mastfoot {
    position: fixed;
    bottom: 0;
  }
}

/* Large devices (large desktops, 1200px and up) */
@media (min-width: @screen-lg-min) {

  /* Pull out the header and footer */
  .mastfoot {
    position: fixed;
    bottom: 0;
  }
}

但是,这会导致它无法在任何设备中修复。当我在媒体查询之外设置以下内容时,它最终会在我也不想要的每个设备中得到修复:

.mastfoot {
    position: fixed;
    bottom: 0;
}

如何让我的网站仅在宽度大于 768 像素的设备上显示固定页脚?

【问题讨论】:

    标签: html css twitter-bootstrap less


    【解决方案1】:

    您在代码中显示的不是 CSS,而是“LESS”。如果您将它用于您的 CSS,它将无法正常工作。您正在为媒体查询使用 LESS 变量,例如:

    @screen-sm-min, @screen-md-min, and @screen-lg-min

    您要确保将变量更改为 CSS 的实际像素尺寸,如下所示:

    /* Large devices (large desktops, 1200px and up) */
    @media (min-width: 1200px) {
    
      /* Pull out the header and footer */
      .mastfoot {
        position: fixed;
        bottom: 0;
      }
    }
    

    当您对 LESS 更加熟悉时,最好在 LESS 文件本身中进行这些修改,然后输出 CSS。虽然这是主观的,但学习 SASS 而不是 LESS 会更加明智。

    但这是一个完全不同的讨论。

    【讨论】:

    • 哇哦。我不知道。这就是我没有深入研究的结果。谢谢@xengravity 一定会探索 SASS!
    • 很高兴有帮助。我认为很多初学者都被这部分所吸引,因为如果你以前没有见过 LESS 或 SASS 是不是很明显。
    猜你喜欢
    • 2020-07-03
    • 2016-07-29
    • 1970-01-01
    • 2021-03-02
    • 2019-08-07
    相关资源
    最近更新 更多