scss 先进的n-child mixins
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了scss 先进的n-child mixins相关的知识,希望对你有一定的参考价值。
@mixin valid-quantity($quantity) {
@if type-of($quantity) != 'number' {
@error 'The "quantity" parameter must be a number!';
}
@if not(unitless($quantity)) {
@error 'The "quantity" parameter must not have a unit!';
}
@if $quantity < 0 {
@error 'The "quantity" parameter must be at least 0!';
}
}
@mixin has-nth($expression, $element: '*') {
&:nth-last-child(#{$expression}):first-child,
&:nth-last-child(#{$expression}):first-child ~ #{$element} {
@content;
}
}
@mixin at-least($quantity, $element: '*') {
@include valid-quantity($quantity);
@include has-nth('n + #{$quantity}', $element) {
@content;
}
}
@mixin at-most($quantity, $element: '*') {
@include valid-quantity($quantity);
@include has-nth('-n + #{$quantity}', $element) {
@content;
}
}
@mixin divisible-by($quantity, $offset: 0, $element: '*') {
@include valid-quantity($quantity);
@include has-nth('#{$quantity}n + #{$offset}', $element) {
@content;
}
}
@mixin has-exactly($quantity, $element: '*') {
@include valid-quantity($quantity);
@include has-nth('#{$quantity}', $element) {
@content;
}
}
@mixin has-odd($element: '*') {
@include has-nth('odd', $element) {
@content;
}
}
@mixin has-even($element: '*') {
@include has-nth('even', $element) {
@content;
}
}
以上是关于scss 先进的n-child mixins的主要内容,如果未能解决你的问题,请参考以下文章
scss mixin的example.scss
scss 用于SCSS的Retina Mixin
scss mixin的gridify.scss
使用 mixin 导入 scss 文件的内容
scss CSS-断点-mixin的1.scss
scss CSS-断点-mixin的vars.scss