javascript - 选择第一个聚合物元素 1
问题描述
我正在使用 Polymer 1 进行 Web 开发,但我遇到了一点点缺乏理解。想象一下:
<div class="value">
<content></content>
</div>
我可以使用选择器轻松设置内容样式.value
。现在我只想设置第一个内容元素的样式。:first-child
等似乎不起作用。
如何选择我<content></content>
的 in Polymer 的不同元素?
谢谢!
解决方案
<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>
推荐阅读
- python - 在 Pandas 中使用多个间隔选择行(pd.Interval 范围对象)
- python - python3 -m pip install VS pip3 install
- laravel-5 - Auth::guard('admin')->user() 在 laravel 5.8 中为 NULL
- c - Vulkan vkCreateInstance - 访问冲突写入位置 0x0000000000000000
- python - 使用 venv 和 python 2.x 创建环境
- git - Git:安全回滚到以前的主人
- bash - 在 bash 中,如何将无限输出流重定向到处理的文件?
- intellij-idea - Intellij 为不应输出任何内容的键输出奇怪的字符
- lua - 考虑到 roblox studio 中的碰撞时如何移动对象
- ios - UIView 和 UICollection 的动态约束