Html CSS:使用特定类选择下一个元素
我有以下html代码,我正在搜索一种方法来选择由Html CSS:使用特定类选择下一个元素,html,css,Html,Css,我有以下html代码,我正在搜索一种方法来选择由class=“selection”标识的span元素,仅在以“cf-”开头的select元素后面: span.select2 selection不是select[id^=“cf-”]的兄弟,因此您需要将该选择器更改为 select[id^="cf-"] + span span.select2-selection { ... } 由于您正在尝试匹配span。select2 selection是span元素的子元素,该元素是select[id^
class=“selection”
标识的span
元素,仅在以“cf-”开头的select元素后面:
span.select2 selection
不是select[id^=“cf-”]
的兄弟,因此您需要将该选择器更改为
select[id^="cf-"] + span span.select2-selection {
...
}
由于您正在尝试匹配span。select2 selection
是span
元素的子元素,该元素是select[id^=“cf-”]
的同级元素,因此应该这样做:
[id*="cf-"] .selection{
//css code here
}
其他信息:
[id*="sometext"]
将选择id包含“sometext”的任何元素
通过在其后放置空格,可以在此元素中指定一个元素
doing.selection将在id包含该tex的元素内选择类为“selection”的元素
select[id^=“cf-”]+span.select2.select2 selection
?或者select[id^=“cf-”]+*。select2 selection
您选择的2 selection元素没有内容,这就是它的宽度为0的原因。您需要为此元素设置显示属性或宽度
[id*="cf-"] .selection{
//css code here
}
[id*="sometext"]