我们可以使用& 运算符
代替important
吗?
下面是我的示例 CSS。有什么方法可以使用 &&
运算符而不是使用 !important
来覆盖基本 CSS?
示例片段
@media only screen and (max-width: 600px) {
body {
background-color: lightblue !important;
}
}
我们可以在 CSS 中用 ampersand operator
代替它吗?
@media only screen and (max-width: 600px) {
body {
background-color: lightblue &&;
}
}
或者它只是 !important in css to $i
最佳答案
我以前从未见过双符号,也无法在任何文档中找到它,我想知道您在哪里找到它(也许是 less 或 sass?)。它不是 !important
的替代品,至少在我的所有最新浏览器中都不是。
至于 !important
,这是覆盖 css 的一种方式,但通常不建议这样做。一般建议是,如果您想要覆盖其他一些 css,请查看它的具体程度并尝试更加具体。这样你就可以证明你真的表达得很清楚,而不是强硬。
有关 !important
的“有争议”使用的详细信息,请参阅此答案:What are the implications of using "!important" in CSS?
关于css - 在 css 中使用 & 运算符来表示重要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55668515/