css - Web 组件 : Adjacent sibling selectors in children

标签 css css-selectors web-component

如何在 Webcomponents 中定位以下内容? (ShadomDom V1 & 自定义元素 V1)

pagination-item + pagination-item {
   margin-right: 10px;
}

在下面...

<pagination>
    <pagination-item></pagination-item>
    <pagination-item></pagination-item>
</pagination>

如果我把它放在分页元素样式中,它不起作用。如果我将 :host + :host 放在分页项中,它就不起作用。

如何在不使用黑客的情况下实现这一目标? 如果你做不到,这似乎是可组合性中的一个大问题......

最佳答案

它应该默认工作(你不是说 margin-left 吗?)。

如果没有,您可以使用 :not(:first-child)在容器中(如果它也是一个 Shadow DOM):

::slotted(pagination-item:not(:first-child)) {
    margin-right: 10px;
}

或者您可以在 <position-item> 中使用它元素:

:host(:not(:first-child)) {
    margin-right: 10px;
}

注意:::slotted 中的选择器伪元素仅限于 performance concerns 的化合物选择器:

While ::content can take any arbitrary selector, ::slotted can only take a compound selector (in the parenthesis). The reason of this restriction is to make a selector style-engine friendly, in terms of performance. In v0, it is difficult to avoid a performance penalty caused by an arbitrary selector which crosses shadow boundaries.

关于css - Web 组件 : Adjacent sibling selectors in children,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41305306/

相关文章:

html - CSS 边框合并

html - 带有 Twitter Bootstrap 的三列流体布局 - clearfixes 搞砸了

html - 悬停时编辑链接

html - 纯CSS标签系统,anchor避免传播到label

css - :not(. MyClass) 选择器与重要

html - 将自定义 CSS 传递给 Polymer 元素

google-maps - 进口 polymer 核心支架破坏谷歌地图

internet-explorer - 在 IE 上的 <table> 或 <select> 中断中使用 dom-repeat

css - 如何使用 bootstrap css 获得 2 行 2 列且不重叠的布局

css - 包含类、子级和相邻同级选择器的 CSS 选择器的等效 XPath 是什么?