【问题标题】:Is there a way to define a media query inside of an existing selector?有没有办法在现有选择器中定义媒体查询?
【发布时间】:2021-09-20 18:57:43
【问题描述】:

有没有办法在现有选择器中定义媒体查询?此外,浏览器似乎支持它。

类似:

.myClass {
    background-color: gray;

    @media (min-width: 600px) {
        display: none !important;
    }
}

这给出了一个错误:

这与这个问题类似,但我的问题是目前是否不支持:

Defining CSS media queries within selectors

【问题讨论】:

  • 这能回答你的问题吗? Defining CSS media queries within selectors
  • @RandomCOSMOS 确实如此,但在我在 Firefox 中的测试中,使用上面的代码会出错。有人说不支持。
  • 看起来浏览器不支持它。 --> 你从哪里读到这样的语法?因为它在 CSS 中不存在
  • @TemaniAfif 我以前没有读过它。我想,我想知道这是否可行。然后我阅读了由 RandomCosmos 链接的帖子。那个帖子提到它好像它有效。
  • @1.21gigawatts 该帖子是在谈论 LESS 而不是 CSS。

标签: html css


【解决方案1】:

.myClass {
    background-color: gray;
}

@media (min-width: 600px) {
    .myClass{
        display: none !important;
    }
}

考虑尝试这样的事情,

此外,如果您只想在代码中使用它,您可以使用 SASS - ext: style.scss 并且在scss文件中插入这段代码也不要忘记链接css文件

.myClass {
    background-color: gray;

    @media (min-width: 600px) {
        display: none !important;
    }
}

【讨论】:

    猜你喜欢
    • 2017-05-09
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-26
    相关资源
    最近更新 更多