如何使用scss从子css中为父css进行样式悬停?

时间:2014-09-16 16:03:06

标签: css sass

我想将hover CSS写入子元素,但是当父元素悬停时。所以像这样:

CSS中我想要的输出:

.parent {
    background:#f8f8f8;
}

.parent .child {
    color:#000;
}

.parent:hover child {
    backgruond:#000;
    color:#fff;
}

什么是#39; m在SCSS中使用:

.parent {
    background:#f8f8f8;
    .child {
        color:#000;
        //now I want to write css here for parent:hover. how can I do this?
    }
}

1 个答案:

答案 0 :(得分:3)

目前尚不清楚你的目的是什么,但我认为就是这个

<强> SASS

.parent {
    background:#f8f8f8;
    .child {
        color:#000;
        //now I want to write css here for parent:hover. how can I do this?
    }

    &:hover {
      background:blue;
      .child {
        color:green;
      }
    }

}

<强> CSS

.parent {
  background: #f8f8f8;
}
.parent .child {
  color: #000;
}
.parent:hover {
  background: blue;
}
.parent:hover .child {
  color: green;
}

使用SASSMeister.com作为测试工具