React js 中 css 样式中 & 的含义是什么

What is the meaning of & in css styling in react js

最近开始学习react js。我注意到在一些 style.ts 文件中 & 已经在 class 声明之前使用了。

export const agGrid = {
    extend: [container],
    '& .ag-theme-material': {
        marginTop: '2rem'
    }
};

有人可以帮忙解释 & 的用途吗?我认为使用的框架是 jss 可以从 package.json 文件

中看到

& 基本上用于表示嵌套 sass/scss.

中的父级
agGrid = {
    '& .ag-theme-material': {
        marginTop: '2rem'
}

将转换为

agGrid .ag-theme-material {
    margin-top: 2rem
}

进入CSS

或者在另一个例子中使用 SCSS

.wrapper {
    &:before, &:after {
        display: none;
    }
}

将转换为

.wrapper::before {
    display: none;
}
.wrapper::after {
    display: none;
}

&用于引用父规则的选择器。

const styles = {
  container: {
    padding: 20,
    '&:hover': {
      background: 'blue'
    },
    // Add a global .clear class to the container.
    '&.clear': {
      clear: 'both'
    },
    // Reference a global .button scoped to the container.
    '& .button': {
      background: 'red'
    },
    // Use multiple container refs in one selector
    '&.selected, &.active': {
      border: '1px solid red'
    }
  }
}

编译为:

.container-3775999496 {
  padding: 20px;
}
.container-3775999496:hover {
  background: blue;
}
.container-3775999496.clear {
  clear: both;
}
.container-3775999496 .button {
  background: red;
}
.container-3775999496.selected, .container-3775999496.active {
  border: 1px solid red;
}

在此处了解更多 - http://cssinjs.org/jss-nested?v=v6.0.1