2017-07-01 72 views
0

我想使我的風格dom-module,因爲我喜歡用@apply CSS指令,我希望我可以這樣做:@apply和樣式DOM模塊不會聚合物工作2.0

<dom-module id="my-styles"> 
<template> 
    <style> 
    html { 
    --big-title: { 
    font-size: 1.3em; 
    text-transform: UPPERCASE; 
    } 
    } 
    </style> 
</template>> 
</dom-module> 

但如果我這樣做:

<dom-module id="my-element"> 
    <template> 
    <style include="my-styles"> 
     h1 { 
     @apply --big-title; 
     } 
    </style> 
    ... 
    </template> 
</dom-module> 

可悲的是這是不行的。我不知道爲什麼。我的問題是我可以使用@apply指令與樣式dom-module解決方案嗎?

回答

1

你應該改爲將你的屬性分配給:host,我會說。

檢查這個例子: http://jsbin.com/dikacewulu/2/edit?html,output

這裏,:host是指包括風格(所以my-element)的元素。如果您真的想要這些規則在html上可用,您可以使用:root

+0

哦,這就是它聽起來所有的代碼都會得到'include'd。我怎麼可能沒有想到之前......謝謝 – user544262772