Structural pseudo-classes allow the selection of elements on the basis of the structure of the entire HTML document which include the position of each element and number of times the occurrence of an element in the document.
A browser treats an HTML document as tree of nodes where nodes are represented by elements their child elements. Structural pseudo-classes allow you to select these nodes and calculate the position of a child node in the node list of a parent node or element.
Lists of The structural pseudo-classes Available in CSS3:
:root :- Select the root element of a document. In HTML the root element is always the HTML element.
For example:
:root{background:red;}
html{background:red;}
:nth-child(N) :-Select the elements on the basis of their position within child elements of a parent element.
For example:
p:nth-child(3){color:blue;}
:nth-last-child(N) :-Selects the elements just as the :nth-child(N) pseudo-class selects but starts the counting from the last child and counts backgrounds.
For example:
tr:nth-last-child(2){background:green;}
:nth-of-type(N) :-Selects the elements on the basis of their position and type within the child elements of a parent element the :nth-of-type() pseudo-class works just as :nth-child() pseudo-class but it only counts the elements that are of the same type as the element to which the rule is applied.
For example:
p:nth-of-type(3){background:blue;}
:nth-last-of-type(N) :- Selects the elements just as the :nth-of-type(N) pseudo-class selects but starts the counting from the last child and counts backgrounds.
For example:
p:nth-last-of-type(2){background:red;}
:first-child :- Selects the first child element of its parent element.
For example:
p:first-child{background:pink;}
:last-child :-Selects the last child element of its parent element.
For example:
p:last-child{background:green;}
:first-of-type :-Selects the first child element of the specified element type.
For example:
p:first-of-type{background:blue;}
:last-of-type :-Selects the last child element of the specified element type.
For example:
p:last-of-type{background:red;}
:only-child :-selects an element if it is the only child element of its parent element.
For example:
p:only-child{background:red;}
:only-of-type :-Selects an element, which is the only child element of its parent element type.
For example:
p:only-of-type {background:red;}
:empty :-Selects the elements that have no child elements.
For example:
p:empty{background:green;}
A browser treats an HTML document as tree of nodes where nodes are represented by elements their child elements. Structural pseudo-classes allow you to select these nodes and calculate the position of a child node in the node list of a parent node or element.
Lists of The structural pseudo-classes Available in CSS3:
:root :- Select the root element of a document. In HTML the root element is always the HTML element.
For example:
:root{background:red;}
html{background:red;}
:nth-child(N) :-Select the elements on the basis of their position within child elements of a parent element.
For example:
p:nth-child(3){color:blue;}
:nth-last-child(N) :-Selects the elements just as the :nth-child(N) pseudo-class selects but starts the counting from the last child and counts backgrounds.
For example:
tr:nth-last-child(2){background:green;}
:nth-of-type(N) :-Selects the elements on the basis of their position and type within the child elements of a parent element the :nth-of-type() pseudo-class works just as :nth-child() pseudo-class but it only counts the elements that are of the same type as the element to which the rule is applied.
For example:
p:nth-of-type(3){background:blue;}
:nth-last-of-type(N) :- Selects the elements just as the :nth-of-type(N) pseudo-class selects but starts the counting from the last child and counts backgrounds.
For example:
p:nth-last-of-type(2){background:red;}
:first-child :- Selects the first child element of its parent element.
For example:
p:first-child{background:pink;}
:last-child :-Selects the last child element of its parent element.
For example:
p:last-child{background:green;}
:first-of-type :-Selects the first child element of the specified element type.
For example:
p:first-of-type{background:blue;}
:last-of-type :-Selects the last child element of the specified element type.
For example:
p:last-of-type{background:red;}
:only-child :-selects an element if it is the only child element of its parent element.
For example:
p:only-child{background:red;}
:only-of-type :-Selects an element, which is the only child element of its parent element type.
For example:
p:only-of-type {background:red;}
:empty :-Selects the elements that have no child elements.
For example:
p:empty{background:green;}
No comments:
Post a Comment