title | slug |
---|---|
CSS 选择器与 XPath 的对比 |
Web/XPath/Comparison_with_CSS_selectors |
{{XsltSidebar}}
本文旨在记录 CSS 选择器和 XPath 之间的区别,以便 Web 开发人员能够更好地为正确的工作选择合适的工具。
XPath 特性 | CSS 等价形式 |
---|---|
ancestor 、parent 或 preceding-sibling 轴 |
{{CSSxRef(":has",":has()")}} 选择器 {{experimental_inline}} |
attribute 轴 |
属性选择器 |
child 轴 |
子代组合器 |
descendant 轴 |
后代组合器 |
following-sibling 轴 |
后续兄弟组合器或接续兄弟组合器 |
self 轴 |
{{CSSxRef(":scope")}} 或 {{CSSxRef(":host")}} 选择器 |