All About CSS3 Selectors

CSS is a style sheet language that helps developing and defining designs, look and formats for HTML pages. Content presentation is taken to a high level with the help of CSS. Document color, fonts and layouts are implemented with the help of CSS. A document is properly segregated and made more flexible and structured with the help of CSS. A CSS3 Selector helps in selecting an element to include style in it. It is important to understand how efficiently CSS codes can be written. Being different is what is wanted by most people. In order to present different CSS styles, it is very important to write efficient selectors. Styling elements without limitations would require an in-depth knowledge in CSS Selectors.

Pseudo-Class in CSS3 Selectors

In order to understand and implement CSS3 Selectors it is important to know that there are basic syntaxes that come with selector types and patterns. Every element has their separate attributes. Pseudo-classes in CSS are used to target elements that are otherwise beyond targeting limits. Elements that cannot be targeted with simple selectors such as id or class and combinators are usually targeted with the help of pseudo-class target tools. Elements are selected on the basis of their relative position, attributes and states before implementing changes in them.

Given below are a few common pseudo-classes used to link states:

:link
:visited
:hover
:active
:focus

There are several new pseudo-classes which are used in targeting elements on the basis of their position within a text tree and in its relation to other existing elements.

CSS 3 selector syntaxes

Substring matching attribute selector

Colon (:) is used as syntax for pseudo-classes before adding a name to the pseudo-class. This is what the syntax looks like:

:pseudo-class {}

In order to target a specific element which is denoted as (e) the element is required to be appended to the beginning of the pseudo-class syntax. The syntax 
for this looks like:

e:pseudo-class {} Pseudo-classes can be used for id and class selectors. The
syntax for this looks like:

#id:pseudo-class {} and .class:pseudo-class {}

How do Pseudo-Classes Work

Getting an overview of the general syntaxes used, it is important to know about new selectors in order to know the effects of the style.

In order to target a root element HTML tags must be used along with CSS selectors to apply changes in background, color and page dimensions.

In order to target a child element in pseudo-class syntax will be:

e:only-child {}

In order to style the text on a page "only-child" is used to target the specific element. Codes are available in CSS3 selector tutorials.

:empty is another important pseudo-class that is used in targeting elements that do not comprise fo children elements and texts. An empty element will look somewhat like:

<p> </p>

An empty element can be targeted with a specific pseudo-class. In order to style a mark-up selectors must be listed into items before targeting them with the specific selectors.

Functions

UI (User Interface) elements can be rightly defined with the help of pseudo-classes. Interface elements, inputs and controls are enabled and disabled with the help of pseudo-classes in CSS3 Selectors.

Provided below are codes for generating different background colours on single line text inputs which greatly depends on its enabled and disabled statuses.

input[type="text"]:enabled { background:#ffc; }
input[type="text"]:disabled { background:#ddd; }

Author Bio : This article is contributed by ValueCoders, a web/mobile application development firm, specialized in web 2.0 application development. One can hire HTML programmer here for effective iPhone application development.

Comments

Popular posts from this blog

How to show only month and year fields in android Date-picker?

How to construct a B+ tree with example

Conflict Serializability in database