Pseudo-classes, Pseudo-elements, Selectors, Combinators

If a pseudo-class is used to define special features of an element, a CSS pseudo-element is used to customize specific parts of an element. On the other hand, a selector is used to select elements with a specified attribute. A combinator is something that states the relationship between selectors.

nth-child

:nth-child() – pseudo-class that selects the element of the same type, depending on the number between the brackets.

nth-last-child

:nth-last-child() – pseudo-class that selects an element of the same type, from end to beginning, the last having the value 1, the penultimate 2, etc.

only-child

:only-child – pseudo-class that selects the mentioned element, only if it is included in another type of element.

target

:target – pseudo-class that highlights the active HTML anchor. The example below will create tabs quickly..

Example

Tab 1 | Tab 2 | Tab 3

Tab 1

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Tab 2

Curabitur tincidunt lacus eget tincidunt tempus

Tab 3

Donec commodo massa metus, non fermentum mi ultricies sit amet.

[attribute=”value”]

[attribute^=value] – (selector) selects the attribute (id, class) whose value starts with a specific text.

Example

This content will be highlighted.
This content will not be highlighted.
This content will also be highlighted.
This content will not be highlighted either.

marker

::marker – pseudo-element that selects the checkbox of a list element, which usually contains a bullet or a number.
Example

Output

  1. Line 1
  2. Line 2
  3. Line 3
  • Line 1
  • Line 2
  • Line 3
  • Line 1
  • Line 2
  • Line 3

Combinators.

  1. descendant selector (space) – matches all elements that are descendants of a specified element.
  2. child selector (>) – selects all elements that are the children of a specified element.
  3. adjacent sibling selector (+) – select an element that is directly after another specific element.
  4. general sibling selector (~) – selects all elements that are next siblings of a specified element.

a) Example

Output

Applicable format

Applicable format

Inapplicable format
b) Example

Output

Inapplicable format

Applicable format

Inapplicable format

Inapplicable format

Inapplicable format

Applicable format

Inapplicable format

c) Example

Output
Inapplicable format

Inapplicable format

Applicable format

Inapplicable format

Inapplicable format

Applicable format

Inapplicable format

d) Example

Output

Inapplicable format

Inapplicable format

Applicable format

Inapplicable format

Applicable format


  1. See also the CSS Tabs post for other ways to make tabs in an easy way.
  2. W3Schools.com

Author: Ovidiu.S

I am quite passionate about this professional area as if I know something - no matter how little - I want to share it with others.

Leave a Reply