scss grandparent_mixin.scss
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了scss grandparent_mixin.scss相关的知识,希望对你有一定的参考价值。
@function up-to($list, $index) {
$l: ();
@each $e in $list {
@if length($l) < $index {
$l: append($l, $e, list-separator($list));
}
}
@return $l;
}
@function parent($selector: null) {
$selector: & !default;
$selector: selector-parse($selector);
$first-parent-selector: nth($selector, 1);
@return nth($first-parent-selector, length($first-parent-selector));
}
@function without-parent($selector: null) {
$selector: & !default;
$selector: selector-parse($selector);
$ancestors: ();
@each $subselectors in $selector {
$ancestors: append($ancestors, up-to($subselectors, length($subselectors) - 1), comma);
}
@debug $ancestors;
@return $ancestors;
}
@function null-selector($selector) {
@if not $selector {
@return true;
}
@else if length($selector) > 0 and length(nth($selector, 1)) > 0 {
@return false;
}
@else {
@return true;
}
}
@mixin grandparent($grandparents, $context: null) {
$context: & !default;
$grandparents: selector-parse($grandparents);
$ancestors: without-parent($context);
$selector: if(null-selector($ancestors), $grandparents, selector-nest($ancestors, $grandparents));
$selector: selector-nest($selector, parent($context));
@at-root #{$selector} {
@content;
}
}
// EXAMPLES
#context {
.jumbotron {
@include grandparent(".container, .container-fluid") {
color: red;
}
}
}
.jumbotron {
@include grandparent(".container, .container-fluid") {
color: red;
}
}
// Outputs:
// #context .container .jumbotron, #context .container-fluid .jumbotron {
// color: red; }
//
// .container .jumbotron, .container-fluid .jumbotron {
// color: red; }
以上是关于scss grandparent_mixin.scss的主要内容,如果未能解决你的问题,请参考以下文章
scss scss_sass_if.scss
scss scss_sass创建-classes.scss
scss 修复基础bug基金会scss基础_functions.scss
导入基本部分 scss 时避免复制 [重复]
分离 SCSS 和 CSS 文件
SCSS--SCSS 常用属性合集