sass - 引用 SCSS 中元素的父级
问题描述
我想要这段代码:
ul li {
...
&:first-child a {
...
}
&:last-child a {
...
}
&.active a {
...
}
a {
...
}
}
变成这样:
ul li {
...
a {
...
&:first-child a ...
}
}
有没有办法引用父母(&应该是ul li)?也许甚至是一个mixin来解决它?
解决方案
像这样使用。对类做任何你想做的事情,link
如果你想在锚下锚定它是 html 验证错误。你必须避免这种情况。
ul {
li {
&.link {
&:first-child {
a {
color: red;
}
}
&:last-child {
a {
color: red;
}
}
}
}
}
输出
ul li.link:first-child a {
color: red;
}
ul li.link:last-child a {
color: red;
}
推荐阅读
- app-store-connect - App Store Connect 的 6.5 英寸 iPhone 的代号 One Simulator 屏幕截图?
- node.js - Flutter 中每次都有不同的 session.id
- magento - 合并多个 Magento 2 商店视图
- php - 如果他们从 9 个选项中单击了一个正确的图像,如何向数据库添加值?
- python - 尝试手动将数据插入 Excel 工作表并在运行程序时保存数据
- html - 输入标签宽度不尊重其父宽度的大小
- javascript - 它如何改变 .hbs 中包含的内容?
- android-emulator - CPU 不支持 KVM 但我想在 AWS Linux 实例中运行 andriod 模拟器
- django - 如何更改 Django 视图子类中的权限?
- github-actions - 从 git 操作下载包时出现问题,导致 URL 损坏