css - 如何在 SCSS 中区分 "#id.class"和 "#id .class"?

标签 css css-selectors sass

我如何使用 SCSS 来区分:

#id.class {
  color: red;
}

和:

#id .class{
  color: blue
} 

因为我需要这样的东西:

#id {
  .class {
    color: red;
  }
  ' ' + .class {
    color: blue;
  }
}

最佳答案

您需要 & 来引用选择器的父级。

Documentation

#id {
  .class {
    color: red;
  }
  &.class {
    color: blue;
  }
}

关于css - 如何在 SCSS 中区分 "#id.class"和 "#id .class"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20702193/

相关文章:

css - 在 scss 元素中导入 bootstrap + grunt + css 编译加载时间

css - 在 SASS 中使用字符串作为变量

javascript - 根据有效电子邮件删除提交按钮类

css - CSS3::selection 伪元素是否也适用于所有子元素?

html - Bootstrap - 无法让按钮居中

java - 在java中检测网页上的 Selenium 元素的最佳方法

html - nth-of-type 选择具有特定类别的前 3 个元素

html - 具有滚动功能的固定高度容器,可根据窗口高度调整大小

CSS font-face - 何时使用多个 src 描述符

jquery - 如何在 IE 的 jQuery CSS 中使用 HTC 行为?