简体   繁体   English

选第一 <content> 含聚合物的元素1

[英]Selcting the first <content> element with polymer 1

I am using Polymer 1 for web-development and I am encountering a small lack of understanding. 我正在使用Polymer 1进行Web开发,但遇到了一些不足的理解。 Imagine the following: 想象以下情况:

<div class="value">
  <content></content>
</div>

I can easily style the content with the .value selector. 我可以使用.value选择器轻松设置内容的样式。 Now I only want to style the First content element. 现在,我只想样式化“第一内容”元素。 :first-child etc. doesn't seem to work. :first-child等似乎无效。

How can I select different elements of my <content></content> in Polymer? 如何在Polymer中选择<content></content>不同元素?

Thanks! 谢谢!

Note that <content> has been deprecated for <slot> . 请注意, <content>已不推荐用于<slot>


To target the first child of the <slot> / <content> , use ::slotted(:first-child) : 要定位<slot> / <content>的第一个子对象,请使用::slotted(:first-child)

 HTMLImports.whenReady(() => { Polymer({ is: 'x-foo', properties: { foo: { type: String, value: 'Hello world!' } } }); }); 
 <head> <base href="https://cdn.rawgit.com/download/polymer-cdn/1.8.0/lib/"> <script src="webcomponentsjs/webcomponents-lite.js"></script> <link rel="import" href="polymer/polymer.html"> </head> <body> <x-foo> <div>first</div> <div>second</div> <div>third</div> </x-foo> <dom-module id="x-foo"> <template> <style> ::slotted(:first-child) { color: red; } </style> <slot></slot> </template> </dom-module> </body> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM