gpt4 book ai didi

CSS [attribute~=value] 选择器行为

转载 作者:行者123 更新时间:2023-11-28 09:12:38 24 4
gpt4 key购买 nike

此选择器用于选择属性值包含给定单词的元素。

例如 title~="image" 将匹配 title="image"title="first image"

但它不会匹配 title="images",即使 "images"包含 "image"。

谁能解释一下为什么?谢谢。

最佳答案

来自CSS Selectors specification :

[att~=val]
Represents an element with the att attribute whose value is a whitespace-separated list of words, one of which is exactly "val". If "val" contains whitespace, it will never represent anything (since the words are separated by spaces). Also if "val" is the empty string, it will never represent anything.

如果你想匹配title="images",你可以使用[att*=val] substring-matching selector相反:

[att*=val]
Represents an element with the att attribute whose value contains at least one instance of the substring "val". If "val" is the empty string then the selector does not represent anything.

[class*="foo"] {
margin: 0;
color: green;
}
<figure class="foo">foo</figure>
<figure class="foo bar">foo bar</figure>
<figure class="bar foo">bar foo</figure>
<figure class="foos bar">foos bar</figure>

关于CSS [attribute~=value] 选择器行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27838509/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com