[英]Polymer 2 apply mixin
I'm trying to get a better understanding of using mixins in Polymer 2: Here is my sample: 我试图更好地理解在Polymer 2中使用mixins。这是我的示例:
<dom-module id="x-test">
<template>
<custom-style>
<style is="custom-style">
html {
--center-on-screen: {
left: 50%;
top: 50%;
position: absolute;
border: solid 1px red;
};
}
</style>
</custom-style>
<style>
.signal {
border-radius: 30px;
height: 30px;
width: 30px;
@apply --center-on-screen;
}
</style>
<div class="signal"></div>
</template>
<script>
'use strict'
class XTest extends Polymer.Element {
static get is() {
return 'x-test';
}
static get properties() {
return {
}
}
static get observers() {
return [];
}
constructor() {
super();
}
ready() {
super.ready();
}
connectedCallback() {
super.connectedCallback();
}
connectedCallback() {
super.connectedCallback();
}
}
customElements.define(XTest.is, XTest);
</script>
</dom-module>
when the code @apply --center-on-screen; 当代码@apply --center-on-screen; in the class, I would expect the div to have the color red and be centered on the screen.
在课堂上,我希望div的颜色为红色并在屏幕上居中。 I have verified it because I had all the code in --center-on-screen in the class .signal.
我已经验证了它,因为我在.signal类的--center-on-screen屏幕上拥有了所有代码。 I moved it into --center-on-screen just for testing purposes.
我出于测试目的将其移至“屏幕中心”。 If anyone can advise me on what i'm doing incorrectly.
如果有人可以告诉我我做错了什么。
**Update ** **更新**
When I move --center-on-screen into :host then it works. 当我将--center-on-screen移动到:host时,它可以工作。 So it looks like this
所以看起来像这样
<style>
:host {
--center-on-screen: {
left: 50%;
top: 50%;
position: absolute;
border: solid 1px red;
}
}
.signal {
border-radius: 30px;
height: 30px;
width: 30px;
border: solid 1px red;
@apply --center-on-screen;
}
</style>
Try to include cd shady css mixin: 尝试包括cd幕后CSS mixin:
<link rel="import" href="../../bower_components/shadycss/apply-shim.html">
CSS custom properties are becoming widely supported, CSS mixins remain a proposal.
CSS定制属性正在得到广泛支持,CSS mixins仍然是一个建议。 So support for CSS mixins has been moved to a separate shim that is optional for 2.0 class-style elements.
因此,对CSS mixins的支持已移至一个单独的垫片,该垫片对于2.0类样式元素是可选的。 For backwards compatibility, the polymer.html import includes the CSS mixin shim.
为了向后兼容,polymer.html导入包含CSS mixin填充程序。 Class-style elements must explicitly import the mixin shim.
类样式元素必须显式导入mixin垫片。
Ref: https://www.polymer-project.org/2.0/docs/upgrade#class-based-elements-import-the-css-mixin-shim 参考: https : //www.polymer-project.org/2.0/docs/upgrade#class-based-elements-import-the-css-mixin-shim
Thanks for posting this query. 感谢您发布此查询。 I was searching some credible resource on how to use css mixins in polymer 2.0 .
我正在寻找一些可靠的资源,以了解如何在Polymer 2.0中使用css mixins。
I had this mixin - 我有这个混搭-
--calendarbox-mixin: {
display:flex;
position:relative;
flex-direction: column;
border-radius: 5px;
--webkit-border-radius:5px;
--moz-border-radius:5px;
width:11vw;
margin:10px 5px;
text-align: center;
height:18vh;
justify-content: space-around;
}
I tried adding it just abover another class where I wanted to use the mixin - 我试图将其添加到我想使用mixin的另一个类之上-
.dayfare_box {
@apply(--calendarbox-mixin);
background: #fbfcfc;
border:2px solid #e2e2e2;
}
The output came without the mixin applied. 输出未应用mixin。 Tried adding in :host and it worked!!
尝试添加:host,它起作用了!!
Just stumbled upon this link and it confirmed my doubt whether I was doing it right. 刚刚偶然发现了这个链接,它证实了我是否做得正确的怀疑。 Thanks for posting :)
感谢您的发布:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.