【问题标题】:Why isn't Shopify compiling my SASS parent selector?为什么 Shopify 不编译我的 SASS 父选择器?
【发布时间】:2017-10-24 21:14:50
【问题描述】:

我正在尝试为其中包含复选框的标签设置样式。当复选框被选中时,我希望标签改变颜色。

<label>
    <input type="checkbox">
</label>

使用 SASS 和 & 符号,这应该是可能的:

input {
    background-color: red;

    &:checked {

        label & {
            background-color: green;
        }
    }
}

我运行了一个测试,这很有效,但是,这在 Shopify 中不起作用。事实上, Shopify 似乎根本没有编译它。我错过了什么吗?

【问题讨论】:

    标签: css sass shopify parent-selector


    【解决方案1】:

    目前任何主流浏览器都不支持选择父级(无论您使用什么 CSS 预处理器)。

    但是,如果您的标签与复选框处于同一级别,那么您可以像这样使用兄弟选择器:

    input:checked + label {
      background: red;
    }
    <input id="aCheckbox" type="checkbox" />
    <label for="aCheckbox">Test</label>

    就 SCSS 而言,它应该看起来像(虽然我还没有测试过):

    input {
        background-color: red;
    
        &:checked {
    
            & + label {
                background-color: green;
            }
        }
    }
    

    【讨论】:

    • 我知道你不能使用 vanilla CSS 选择父级,但是这对于 SASS 是可能的,尽管它似乎没有被记录。我已经对其进行了测试,它使用 grunt-contrib-sass 任务工作。它似乎在 Shopify 中不起作用。我想知道是否可以更新 Shopify 编译器之类的。
    • @MichaelLynch 你能验证一下吗? (例如,创建一个代码笔?)我也渴望看到这项工作! :)
    • 另外:也许它会起作用,将您的 SCSS 编译为纯 CSS 并在您的 Shopify 应用程序中使用它?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-07
    • 1970-01-01
    • 1970-01-01
    • 2022-09-30
    • 2016-08-30
    • 1970-01-01
    相关资源
    最近更新 更多