--- title: Comparison of CSS Selectors and XPath slug: Web/XPath/Comparison_with_CSS_selectors translation_of: Web/XPath/Comparison_with_CSS_selectors original_slug: Web/CSS/CSS_Selectors/Comparison_with_XPath ---
本文旨在记录CSS选择器和XPath之间的区别,以便Web开发人员能够更好地为正确的工作选择合适的工具。
XPath feature | CSS equivalent |
---|---|
ancestor , parent or preceding-sibling axis |
{{CSSxRef(":has",":has()")}} selector {{experimental_inline}} |
attribute axis |
Attribute selectors |
child axis |
Child combinator |
descendant axis |
Descendant combinator |
following-sibling axis |
General sibling combinator or adjacent sibling combinator |
self axis |
{{CSSxRef(":scope")}} or {{CSSxRef(":host")}} selector |