4

更新:聚合物文档现已更新以反映以下答案

我正在做一个聚合物 1.0 应用程序。

我正在尝试在部分屏幕上水平布局一些纸质工具栏。
看来我可以让 iron-flex-layout 的 @apply(--layout-horizo​​ntal) 处理某些元素,但不能处理其他元素。

我在下面进行了一个小测试以显示发生了什么。
有趣的是,如果我将 --layout-horizo​​ntal 样式的内容复制到 chrome 开发工具中的标签中,它就可以工作。如果我只是将 --layout-horizo​​ntal 的内容复制到新样式中,它也可以工作。

这是正在发生的事情的示例。

第一个 div 是 0.5 到 1.0 迁移指南中的示例。
第二个 div 是示例,但尝试布局一个部分而不是一个跨度。
第三行是我明确复制和应用 --layout-horizo​​ntal 样式的地方。

在此处输入图像描述

<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/iron-flex-layout/iron-flex-layout.html">

<dom-module id="layout-test">

    <style>
        /* Example from migration guide */
        .header {
            @apply(--layout-horizontal --layout-center);
        }

        /* A hack that makes it work */
        .hack {
            display: -ms-flexbox;
            display: -webkit-flex;
            display: flex;

            -ms-flex-direction: row;
            -webkit-flex-direction: row;
            flex-direction: row;
        }
    </style>

    <template>

        <!-- Working example from migration guide  -->
        <div class="header">
            <img src="https://www.polymer-project.org/images/logos/lockup.svg">
            <span class="name">name</span>
        </div>

        <!-- This example does not work  -->
        <div class="header">
            <img src="https://www.polymer-project.org/images/logos/lockup.svg">
            <section class="name">name</section>
        </div>


        <!-- This hack works fine -->
        <div class="hack">
            <img src="https://www.polymer-project.org/images/logos/lockup.svg">
            <section class="name">name</section>
        </div>

    </template>
</dom-module>
<script type="text/javascript">
    Polymer({
        is: 'layout-test'
    });
</script>

完整项目可在此处获得https://github.com/nburn42/polymer-1.0-LayoutTest

谢谢,
内森

4

1 回答 1

15

根据聚合物 github 上的 issue 1601 ( https://github.com/Polymer/polymer/issues/1601 ),他们改变了自定义 CSS mixins 可以传递给@apply 的方式。您必须将它们分开,而不是在单个 @apply 调用中链接多个 mixin。这意味着以下代码片段:

  .header {
        @apply(--layout-horizontal --layout-center);
    }

变成:

  .header {
        @apply(--layout-horizontal);
        @apply(--layout-center);
    }

Polymer 确实需要更新其网站上的文档和示例,因为这样的更改未得到反映将导致采用 Polymer 的人减少。

于 2015-06-06T18:04:02.830 回答