gpt4 book ai didi

css - Sass 占位符选择器和 Modernizr .no 类

转载 作者:行者123 更新时间:2023-11-28 18:33:46 28 4
gpt4 key购买 nike

假设我在 Sass 中有一个占位符选择器。在该选择器中,我编写了一些样式,显然我需要使用 Modernizr 检查功能。

问题似乎是您要使用 modernizr 提供的 .no-generatedcontent 或 .generatedcontent 类,但它们无法使用,因为一旦占位符选择器完成工作,它们将位于错误的层次结构位置。

我能想到的解决这个问题的唯一方法是将它们放在占位符选择器之外,但这会弄乱我的样式,而 Sass 旨在帮助使我的样式更有条理。

关于如何解决这个问题有什么想法吗?

这是我的意思的一个例子:

<html>一旦 modernizr 完成它的工作,在我的页面顶部标记:

<html class="js flexbox flexboxlegacy canvas canvastext webgl touch geolocation postmessage websqldatabase indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow textshadow opacity cssanimations csscolumns cssgradients cssreflections csstransforms csstransforms3d csstransitions fontface generatedcontent video audio localstorage sessionstorage webworkers applicationcache svg inlinesvg smil svgclippaths wf-allumistd-n1-active wf-freightsanspro-n3-active wf-automate-n4-active wf-automate-n7-active wf-active">

现在,假设我有一个名为 %styles 的占位符选择器

%styles {
li {
this: this;
}
.no-generatedcontent li {
this: that;
}
}

现在,我将在我的代码中的某处使用这个占位符,如下所示:

.main {
section {
.box-area {
color: red;
@extend %styles;
}
}
}

在我看来,显然 modernizr 类位于错误的位置,因此无法产生任何效果。这是一种层次结构问题。我可以通过将它放在占位符之外来解决它,但是我必须单独 @extend 它并且我的 sass 代码变得一团糟,这是我开始使用 sass 来保持我的样式整洁的主要原因。

有什么想法吗?

最佳答案

萨斯:

%styles {
li {
border: 1px solid red;

.no-generatedcontent & { // note the location of the & here
border: 1px solid red;
}
}
}

.main {
section {
.box-area {
color: red;
@extend %styles;
}
}
}

CSS:

.main section .box-area li {
border: 1px solid red; }

.no-generatedcontent .main section .box-area li, .main section .no-generatedcontent .box-area li {
border: 1px solid red;
background: #CCC; }

.main section .box-area {
color: red; }

使用 @extend 时似乎有一个错误(查看它如何在 .no-generatedcontent 行上生成 2 个选择器?Sass 3.2.3)。如果我改用 mixin,则不会发生这种情况:

.main section .box-area {
color: red; }

.main section .box-area li {
border: 1px solid red; }

.no-generatedcontent .main section .box-area li {
border: 1px solid red;
background: #CCC; }

关于css - Sass 占位符选择器和 Modernizr .no 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13453674/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com