Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the selector [class^="span"] do?

I can't work out what this is:

Line 33 of 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"] 
like image 741
PhilD Avatar asked Sep 09 '11 19:09

PhilD


People also ask

What is the use of SPAN class?

The <span> tag is an inline container used to mark up a part of a text, or a part of a document. The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute. The <span> tag is much like the <div> element, but <div> is a block-level element and <span> is an inline element.

What does the span element do?

<span>: The Content Span element The <span> HTML element is a generic inline container for phrasing content, which does not inherently represent anything. It can be used to group elements for styling purposes (using the class or id attributes), or because they share attribute values, such as lang .

Is span a selector?

Every HTML tag has a corresponding selector, for example: div , span , img .

How do I select a span class in CSS?

If you want to makes some particular text or any other content different from the rest, you can wrap it in a span tag, give it a class attribute, then select it with the attribute value for styling. In the examples below, I change the color , background-color , and font-style of some text by wrapping it in a span tag.


1 Answers

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> 

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.

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

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

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

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

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

like image 136
SamGoody Avatar answered Sep 24 '22 01:09

SamGoody