CSS 选择器与 XPath 的对比

本文旨在记录 CSS 选择器和 XPath 之间的区别,以便 Web 开发人员能够更好地为正确的工作选择合适的工具。

XPath 特性 CSS 等价形式
ancestorparentpreceding-sibling :has() 选择器 实验性
attribute 属性选择器
child 子代组合器
descendant 后代组合器
following-sibling 通用兄弟组合器相邻兄弟组合器
self :scope:host 选择器