The main usage of Cascading Style Sheets selectors is that it is used for binding style properties to elements in the document. The Cascading Style Sheets Level 3 selectors are compatible with many modern browsers thus making its usage more powerful and popular. In general a CSS selector is made up of a pattern that is matched against all elements in the document tree.
That is to explain in brief a pattern has set of conditions placed in it and when all conditions in the pattern are satisfied or in other words returns true value then selector is applied which means the declarations placed within the rule are applied to the element or elements that match.
That is in general the selectors take the following notation namely:
expression element ? boolean
The above means that the specification placed defines whether that element matches the selector. A set of elements or a single element from the set of elements can be selected by means of expressions defined as above and these expressions gets applied across all the elements in a sub tree.
First one must know the basic categories of selectors before going in detail.
In broad there are two basic categories of selectors. They are namely:
Let us see what each of these means:
A simple selector consists of either a type selector which is denoted by pattern E and thereby matches any E element or the universal selector which is denoted by pattern * and thereby matches all element in the document followed by zero or more attribute selectors which represents a pattern denoted as E[attr] thereby matching any E element that has an attr attribute, regardless of its value, ID selectors denoted by pattern #footer and there by matches any element with an id equal to footer, or pseudo-classes.
The combined selector is also called as contextual selector and this contains two or more simple selectors separated by a combinator.
The Cascading Style Sheets Level 2 also had selectors feature in it. There are some differences and some new features that are implemented in the Cascading Style Sheets Level 3. Let us see some of them namely:
In Cascading Style Sheets Level 3 the definitions that we defined above for simple and combined selectors and many more has been redefined. That is in other words let us see how the simple selector is represented in Cascading Style Sheets Level 3.In Cascading Style Sheets Level 3 simple selector is defined as sequence of simple selectors. Like that there is change in all definition which we will see in coming sections as we define each module in detail.
Introduction of optional namespace component:
Introduction and Usage of an optional namespace component which is allowed for specification of an element type in Cascading Style Sheets Level 3. We know that type selector matches every instance of a particular element type that is in other words has a pattern denoted by pattern E and thereby matches any E element. Also a universal selector is denoted by pattern * and matches all element in the document. This new optional component usage namely the optional namespace component of Cascading Style Sheets Level 3 can be used with any of these type element selectors or the universal selector and attribute selectors.
Introduction of new combinator:
Combinators in general are used to separate the two or more simple selectors that make up a combined. There is a new combinator introduced in CSS3 namely the Indirect Adjacent combinator. Detailed explanation of types of combinators available along with the usage, syntax with the explanation in detail on the new combinator also will be made in coming sections.
Substring matching attribute selectors:
This new concept of Substring matching attribute selectors in Cascading Style Sheets Level 3 helps developers to match substrings in the value of an attribute.
The new pseudo-classes in Cascading Style Sheets Level 3 like :target pseudo-class helps to link a certain element within the document. There are many new pseudo-classes in Cascading Style Sheets Level 3 like the above .To mention some more are namely like :enabled and :disabled pseudo-classes which helps programmers to control the appearance of user interface elements like whether enabled or disabled as needed by them. There are still a lot more new pseudo-classes in Cascading Style Sheets Level 3 which all will be dealt in detail in coming sections.
The new pseudo-elements in Cascading Style Sheets Level 3 like ::selection pseudo-element helps to control the way a selected text would appear like color or any properties. Here we can note that a special notation namely "::" has been used in Cascading Style Sheets Level 3.
Modularization of Selectors:
As we have seen in our earlier section the modularization is the major concept of Cascading Style Sheets Level 3 which adds to its powerful ability. The selectors concept of Cascading Style Sheets Level 3 is also a CSS3 Module and thereby becomes an independent specification for handling.