Nesting CSS classes(嵌套 CSS 类)
问题描述
我可以执行以下操作吗?
Can I do something like the following?
.class1{some stuff}
.class2{class1;some more stuff}
推荐答案
原生 CSS 不可能.但是你可以使用类似的东西:
Not possible with vanilla CSS. However you can use something like:
- Sass
Sass 让 CSS 再次变得有趣.萨斯是一个CSS3的扩展,添加嵌套规则、变量、混合、选择器继承,等等.已翻译使用格式良好的标准 CSS命令行工具或网络框架插件.
Sass makes CSS fun again. Sass is an extension of CSS3, adding nested rules, variables, mixins, selector inheritance, and more. It’s translated to well-formatted, standard CSS using the command line tool or a web-framework plugin.
或者
- 少
而不是构造长选择器用于指定继承的名称,在 Less 中你可以简单地将选择器嵌套在里面其他选择器.这使得继承清晰和样式表更短.
Rather than constructing long selector names to specify inheritance, in Less you can simply nest selectors inside other selectors. This makes inheritance clear and style sheets shorter.
示例:
#header {
color: red;
a {
font-weight: bold;
text-decoration: none;
}
}
这篇关于嵌套 CSS 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:嵌套 CSS 类
基础教程推荐
- npm start 错误与 create-react-app 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
