Subscribe:

Ads 468x60px

dropdown

Social Icons

CSS: ID Selector - Learn CSS for Free and Fun


ID Selectors

ID selectors are also used to define styles for an object with a unique ID. It is mostly used with
layers as layers are always defined by a unique ID. An ID selector is defined as a #. The general
syntax for an ID selector is #IDSelector{Property:Value;}. ID selectors apply to exactly one
element.

There are TWO types of ID selectors:


Solitary ID selectors 

It can apply to any element with an ID matching the ID of the selector. Any element with #idname syntax will have Solitary ID selectors applied over it.

The following ID selector will apply to an element that has an id attribute with a value of "red":

#red {color: red;}


ID selectors

This ID selector is associated with a particular type of element in a page. This ID selector will have the syntax elementname# idname and will apply only to the
element with this ID.

The following ID selector will apply to a p element that has an id attribute with a value of “para1":

p#para1{
text-align: left;
color: blue;
}


ID selectors are also used for defining styles for HTML elements. These selectors are used to
define a style for an object with a unique ID. The ID selector is mostly used with layers as
layers are always defined by a unique ID.

An ID selector is defined as a # and the general syntax for an ID selector is shown here.
Hash followed by the ID selector and then the property and its value within braces. ID selectors
apply to exactly one element.

There are TWO types of ID selectors: Solitary ID selectors and ID selectors.

Solitary ID selector is a general ID selector that can apply to any element with an ID matching
the ID of the selector. Any element with #idname syntax will have Solitary ID selectors applied
over it.

The solitary ID selector in our example will apply to an element that has an id attribute with a
value of "red":

ID selector is associated with a particular type of element in a page. This ID selector will have
the syntax element-name#idname and will apply only to the element with this ID. It must be
noted here that an ID comprises only alpha numeric characters and hyphens and does not
include any other characters, underscores or spaces, nor can an ID start with a numeral.
The example shows the ID selector that will apply to a p element that has an id attribute with
a value of "para1":

0 comments:

Post a Comment