css - mixin 中的媒体查询被覆盖

标签 css sass media-queries google-chrome-devtools

我制作了一个“响应式属性”mixin,它将一个 css 属性及其在五个不同断点处的值作为参数:

@mixin responsiveProp ($prop, $xs, $sm, $md, $lg, $xlg) {
  @media only screen and (min-width: 0px) {
    #{$prop}: $xs;
  }
  @media only screen and (min-width: 768px) {
    #{$prop}: $sm;
  }
  @media only screen and (min-width: 992px) {
    #{$prop}: $md;
  }
  @media only screen and (min-width: 1200px) {
    #{$prop}: $lg;
  }
  @media only screen and (min-width: 1440px) {
    #{$prop}: $xlg;
  }
}

例如@include responsiveProp(height, 1300px, 900px, 550px, 500px, 500px);

这通常作为减少 CSS 中 LOC 的一种方法非常有效,但是当在 Chrome 开发工具中使用智能手机布局测试上述示例时,尽管宽度小于 768 像素,但 $xs 断点被 $sm 断点覆盖。我不明白为什么会这样。有什么想法吗?

最佳答案

我忘了将它添加到我的 index.html 中:<meta name="viewport" content="width=device-width, initial-scale=1"> .这解决了问题。

关于css - mixin 中的媒体查询被覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39352229/

相关文章:

jquery - 使用特定的 url 设置 iframe 的样式

html - 在浏览器调整大小时将元素移动到新行

html - 自定义复选框,在 :hover and :checked. 上更改不起作用

css - 如何修复使用 CSS3 媒体查询时不正常的菜单?

css - Bootstrap 3 - 较小屏幕上的列顶部边距

jquery - Chrome bumping span 元素在 div 的其余部分下方

html - 父 div 使用剪辑路径剪切子 div

css - Bootstrap 4 将图像移出卡片标题的容器

css - 自定义属性被忽略 : not scoped to the top-level :root element

css - 坚持在此布局上进行媒体查询的最佳方法