是否可以在属性选择器的中间使用CSS通配符? [英] Is it possible to use a CSS wildcard in the middle of an attribute selector?

查看:149
本文介绍了是否可以在属性选择器的中间使用CSS通配符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些生成的CSS,并希望使用一些css可以选择

  < p id =loremIndexIpsum>此处的文字< / p> 

使用 lorem Ipsum 忽略索引。类似的:

  p#lorem * Ipsum 
{
}



我可以生成一些类,但想知道这是否可能与CSS。

解决方案

您不能使用这样的通配符,而是要获得所需的结果(ID以 lorem 开头, Ipsum ),您可以使用属性start-with和ends - with selectors instead。

  p [id ^ =lorem] [id $ = Ipsum] 

请记住,通过链接多个属性选择器> p 类型选择器),您在同一个元素上与它们的所有元素进行AND匹配。



jsFiddle demo


I have some generated CSS and would like to use some css that could select e.g.

<p id="loremIndexIpsum">Text in here</p>

Using on lorem and Ipsum disregarding Index. Something similar to:

p#lorem*Ipsum
{
}

I can generate some more classes, but wondered if this was possible with CSS.

解决方案

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"]

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 demo

这篇关于是否可以在属性选择器的中间使用CSS通配符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆