【发布时间】:2015-07-31 02:18:01
【问题描述】:
我从 0.5 版开始就没有使用过 Polymer,所以我决定再试一次。我在使用 :host 和 ::content 选择器时遇到了一些问题,特别是考虑到我发现 :host 选择器仅在我的样式标签放在标签之外时才有效。
无论如何,我的问题是我无法让主机选择器工作,除非我在 CSS 中的 :host 下指定 display: block。其次,显然选择器“:host”和“:host ::content”之间没有区别。我正在尝试仅对插入到内容标签中的内容进行样式化,而不使用包装元素。
这是来自 custom-element.html 的代码:
<dom-module id="custom-element">
<style>
/* Demonstrating how to specify inserted content
any content added here is styled
*/
:host ::content
{
color: green;
}
/* This CSS targets the custom-element tag itself */
:host
{
padding: 4px;
background-color: gray;
}
</style>
<template>
<!-- Title will be placed here before the content -->
<h2 id="title">{{title}}</h2>
<!-- Any content inside the tag will be placed here -->
<content></content>
</template>
....
这里是在 index.html 中使用它的相关位置:
<!-- Auto-binding templates -->
<template id="t" is="dom-bind">
<h1>Your input was <span>{{inputValue}}</span></h1>
<br>
<input is="iron-input" bind-value="{{inputValue}}">
<input type="button" value="Add to list" onClick="pushItem()">
<ul>
<!-- Repeating templates -->
<!-- Here, the items attribute specifies the array of items to bind to. -->
<template id="repeatingList" is="dom-repeat" items="{{listItems}}">
<!-- This demonstrates that we can find the index and data for every item in the specified array -->
<li>Array index <span>{{index}}</span>- <span>{{item}}</span></li>
</template>
</ul>
<br>
<custom-element title="{{inputValue}}"><p>Lorem ipsum!</p></custom-element>
</template>
它是这样显示的(灰色背景不会出现在元素内容的后面,颜色应该只应用于内容标签):https://goo.gl/photos/p2EjTSjySCh2srY78
【问题讨论】:
-
您的链接已损坏。
标签: javascript css polymer web-component shadow-dom