如何使用 title~= 必须包含 space 的 CSS 属性选择器?
How to do CSS attribute selector with title~= that has to contain a space?
我有以下 select 或:
.post-link[title~=Corporate]
现在,我只需要 select 标题仅在最开始有单词 "Corporate" 的元素,而不是标题中的其他地方。
所以我有两个选择:
1) 创建一个 selector 只检查标题的开头,然后跳过其他最终跟随 or
2) 创建一个 selector 可以包含一个 space 加上一个 '|'喜欢:
.post-link[title~=Corporate |]
因为在我的情况下所有标题都以
开头
"Keyword |"
(公司 | i.g。)
但是当我使用时 css 不再工作:
.post-link[title~=Corporate |]
我也试过:
.post-link[title~=Corporate |]
无效。这该怎么做?我找不到 Google.
的答案
非常感谢!
这应该可以做到。
.post-link[title|="Corporate "]
|=
运算符匹配开头。
Now I need, instead, to select only elements whose title have the word "Corporate" only at the very beginning, not somewhere else in the title.
您可以使用 [title^='Corporate']
:
[title^='Corporate'] {
background: lightgreen;
}
<div title='Corporate foo bar'>Test case 1</div>
<div title='foo Corporate bar'>Test case 2</div>
<div title='Corporate | foobar'>Test case 3</div>
E[foo^="bar"]
: an E element whose "foo" attribute value begins exactly with the string "bar"
我有以下 select 或:
.post-link[title~=Corporate]
现在,我只需要 select 标题仅在最开始有单词 "Corporate" 的元素,而不是标题中的其他地方。
所以我有两个选择:
1) 创建一个 selector 只检查标题的开头,然后跳过其他最终跟随 or
2) 创建一个 selector 可以包含一个 space 加上一个 '|'喜欢:
.post-link[title~=Corporate |]
因为在我的情况下所有标题都以
开头"Keyword |"
(公司 | i.g。)
但是当我使用时 css 不再工作:
.post-link[title~=Corporate |]
我也试过:
.post-link[title~=Corporate |]
无效。这该怎么做?我找不到 Google.
的答案非常感谢!
这应该可以做到。
.post-link[title|="Corporate "]
|=
运算符匹配开头。
Now I need, instead, to select only elements whose title have the word "Corporate" only at the very beginning, not somewhere else in the title.
您可以使用 [title^='Corporate']
:
[title^='Corporate'] {
background: lightgreen;
}
<div title='Corporate foo bar'>Test case 1</div>
<div title='foo Corporate bar'>Test case 2</div>
<div title='Corporate | foobar'>Test case 3</div>
E[foo^="bar"]
: an E element whose "foo" attribute value begins exactly with the string "bar"