PostCSS Custom Selector
安装(暂未发布)
$ npm install postcss-custom-selector
快速开始
// dependenciesvar fs = var postcss = var selector = // css to be processedvar css = fs // process css using postcss-custom-selectorvar output = css console
或者:
var output = css
input.css:
@
你将得到:
CSS 语法
A custom selector is defined with the @custom-selector
rule:
@custom-selector = @custom-selector <extension-name> <selector>;
This defines a custom selector which is written as a pseudo-class with the given <extension-name>
, and represents a :matches()
selector using the provided <selector>
as its argument.
For example, if an author wanted to easily refer to all heading elements in their HTML document, they could create an alias:
@/* etc */
如何使用
伪元素/伪类
你可以使用
:
自定义一个伪类。::
自定义一个伪元素。
例如,模拟一个 :any-link 选择器:
input.css:
@
output:
多个选择器
@custom-selector
类似 CSS :matches()
选择器,但是目前不支持在同一个选择器中调用多个自定义选择器,例如:
@@
将会输出错误的 CSS 代码。
Grunt
grunt; grunt;
Gulp
var gulp = ;var postcss = ; gulp;
选项
extensions
(默认: {}
)
该选项允许你自定义一个对象来设置 <extension-name>
(选择器别名)和 <selector>
,这些定义将覆盖 CSS 中相同别名的 @custom-selector
。
var options = extensions: ':--any' : 'section, article, aside, nav' var output = css;
input.css
@/* 不会生效 */
output:
贡献
- 安装相关依赖模块
- 尊重编码风格(安装)
- 运行测试
$ git clone https://github.com/postcss/postcss-custom-selector.git
$ git checkout -b patch
$ npm install
$ npm test