Skip to content
This repository has been archived by the owner on May 7, 2023. It is now read-only.

Latest commit

 

History

History
34 lines (22 loc) · 922 Bytes

css-sibling-selectors.md

File metadata and controls

34 lines (22 loc) · 922 Bytes

What is the difference between '+' and '~' sibling selectors?.

Answer

The General Sibling Selector ~ selects all elements that are siblings of a specified element.

The following example selects all <p> elements that are siblings of <div> elements:

div ~ p {
  background-color: blue;
}

The Adjacent Sibling Selector + selects all elements that are the adjacent siblings of a specified element.

The following example will select all <p> elements that are placed immediately after <div> elements:

div + p {
  background-color: red;
}

Good to hear

Additional links