我有一个 html 代码如下:
<div id="select_a_boundary" class="dataset_select2">Homes name</div>
我为此写了一个 xpath 表达式:
//div[@id = 'select_a_boundary' and @class = 'dataset_select2']
相同的 CSS 选择器是什么?
最佳答案
首先,如果您正在使用 id
,则不需要使用类,其次,如果您愿意,您可以选择具有 id select_a_boundary
的元素使用
#select_a_boundary {
/* Styles goes here */
}
Note: Am not selecting the element which has that id and that class as here, id is sufficient as it has to be unique, if you are using the id for multiple elements than it's invalid
根据您的意见
div[id=select_a_boundary][class=dataset_select2] {
color: red;
}
或者更简单的一个(来源:Jack)
#select_a_boundary.dataset_select2 {
color: red;
}
Note: Still I would recommend you to use
#select_a_boundary
is more than enough
关于html - 需要 XPATH 表达式的等效 CSS 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17828871/