css - CSS 链接嵌套样式
问题描述
我需要创建很多链接样式:
a:link {color: one;}
a:visited {color: two;}
a:hover {color: three;}
a:active {color: four;}
但对于 a.1 - a.10
有什么办法可以将代码切割成更紧凑的变体?
谢谢。
解决方案
你不能用简单的 CSS 来做到这一点,你可以使用 SASS 来做你想做的事。
您将能够创建类似的东西:
.my-class-1 a, .my-class-2 a {
:link {
color: one;
}
:visited {
color: two;
}
[...]
}
如果你的类需要多种样式,你仍然可以嵌套你的样式a
,它仍然更容易阅读和更快地编写:
.my-class-1 a {
:link {
color: one;
}
:visited {
color: two;
}
[...]
}
.my-class-2 a {
:link {
color: three;
}
:visited {
color: four;
}
[...]
}
推荐阅读
- phoenix-framework - data-to 如何作为 phoenix 中按钮的属性工作?
- javascript - 将 MongoDB Stitch 查询中的 objectID 或 _id 转换为字符串并映射它
- javascript - 更改chartJs中yAxis的标签
- c++ - std :: 数组的目的是什么
? - excel - 如果 activeworkbook.name = "inventariogen.xls" 代码存储在个人宏工作簿中并在 workbook_open 时触发,则运行时出现错误 91
- angular - 离子/角度与 Angular 9 不兼容
- apache-kafka - Consumer.subscribe()时会发生什么,即使kafka中没有broker
- ios - Revenuecat React-Native iPad Purchases.purchasePackage - 承诺不会解决
- rxjs - 同步 RxJs 取消订阅不起作用
- python - python中的错误:使用if/else时不会存储变量