Is it possible to use a CSS wildcard in the middle of an attribute selector?(是否可以在属性选择器中间使用 CSS 通配符?)
问题描述
我有一些生成的 CSS,想使用一些可以选择的 CSS,例如
I have some generated CSS and would like to use some css that could select e.g.
<p id="loremIndexIpsum">Text in here</p>
在 lorem
和 Ipsum
上使用,而忽略 Index
.类似于:
Using on lorem
and Ipsum
disregarding Index
. Something similar to:
p#lorem*Ipsum
{
}
我可以生成更多类,但想知道这是否可以通过 CSS 实现.
I can generate some more classes, but wondered if this was possible with CSS.
推荐答案
不能使用这样的通配符,而是要得到想要的结果(ID 以 lorem
开头,以 结尾>Ipsum
) 你可以使用 属性开头和结尾选择器 相反,像这样:
You can't use a wildcard like that, but to get the desired result (ID starts with lorem
and ends with Ipsum
) you can use the attribute starts-with and ends-with selectors instead, like so:
p[id^="lorem"][id$="Ipsum"]
请记住,通过像这样链接多个属性选择器(连同 p
类型选择器),您正在对同一元素上的所有属性选择器进行 AND 匹配.
Remember that by linking multiple attribute selectors like this (along with the p
type selector), you're doing an AND match with all of them on the same element.
jsFiddle 演示
这篇关于是否可以在属性选择器中间使用 CSS 通配符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!