最后如何引用父选择器? [英] How do I reference the parent selector at the end?

查看:38
本文介绍了最后如何引用父选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何转:

.btn-primary {
  .open .dropdown-toggle.btn-primary { ... }
}

进入

.btn-primary {
  .open .dropdown-toggle& { ... }
}

在 .dropdown-toggle 之后我一直收到无效的选择器

I keep getting invalid selector after .dropdown-toggle

推荐答案

如果你阅读了完整的错误,应该是这样的:

If you read the complete error, it should say this:

"&"只能用在复合选择器的开头.

"&" may only be used at the beginning of a compound selector.

但是,.dropdown-toggle.btn-primary.btn-primary.dropdown-toggle 相同.所以将父选择器放在开头:

However, .dropdown-toggle.btn-primary is the same as .btn-primary.dropdown-toggle. So place the parent selector at the beginning:

.btn-primary {
  .open &.dropdown-toggle { color: blue; }
}

Sass 3.4 开始,您可以这样做:

As of Sass 3.4, you can do that like this:

.btn-primary {
  .open .dropdown-toggle#{&} { color: blue; }
}

这篇关于最后如何引用父选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆