选择器[class ^ =" span"]有什么作用? [英] What does the selector [class^="span"] do?

查看:267
本文介绍了选择器[class ^ =" span"]有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚这是什么:

I can't work out what this is:

http://twitter.github.com/bootstrap/assets/css/bootstrap-1.2.0.min.css

.row [class^="span"] {
  display: inline;
  float: left;
  margin-left: 20px;
}



我理解了风格,但我从来没有见过这个

I understand the style but I've never seen this before

[class^="span"]


推荐答案

这意味着以span开头的类,例如:

This means a class beginning with the word "span", such as:

<div class="spanning"></div>

^ 符号取自正则表达式,其中此符号指字符串的开头。

The ^ symbol is taken from regular expressions, wherein this symbol refers to the beginning of a string.

应该注意,这将检查类属性的开头,而不是类名的开头。这意味着它不匹配所述选择器:

It should be noted that this checks for the beginning of the class attribute, not the beginning of the classname. Which means it will not match said selector:

<div class="globe spanning"></div>

上述元素有两个类,第二个以span开头, class 以globe开头,而不是以span开头,它将不匹配。

The above element has two classes, the second of which begins with "span" - but since the attribute class begins with "globe", not with "span", it will not match.

code> [class * = span] ,它将返回包含span的所有类,但也会返回其他类,例如 wingspan

One could use [class*=span], which would return all classes containing span, but that would also return other classes, such as wingspan.

AFAIK,获取以字符串开头的类的方法是使用双选择器:

AFAIK, the way to get classes that begin with a string are to use a double selector:

.row [class^="span"], .row [class*=" span"]{}

这将返回以span开头的类,无论是在属性开头还是在中间。

This will return the class beginning with span, whether at the beginning of the attribute, or in the middle.

我还记得在 DOMParser 使用的本地选择器引擎中使用解决方案。

(I also recall working in a solution in the homegrown selector engines used by DOMParser).

这篇关于选择器[class ^ =&quot; span&quot;]有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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