Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In CSS, the symbols you mention are:</p> <ul> <li><code>&gt;</code> is the the child combinator;</li> <li><code>+</code> is the adjacent sibling combinator;</li> <li><code>~</code> is the general sibling combinator.</li> </ul> <p>The difference between them is this:</p> <p><code>#store &gt; .shoppingCart { background-color: red; }</code></p> <pre><code>&lt;div class=shoppingCart&gt;This will not be targeted&lt;/div&gt; &lt;div id=store&gt; &lt;div class=shoppingCart&gt;This WILL be targeted&lt;/div&gt; &lt;div class=shoppingCart&gt;This WILL ALSO be targeted&lt;/div&gt; &lt;div class=inner&gt; &lt;div class=shoppingCart&gt;This will not be targeted&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=shoppingCart&gt;This will not be targeted either&lt;/div&gt; &lt;div class=shoppingCart&gt;Neither will this&lt;/div&gt; </code></pre> <p>The <code>&gt;</code> combinator selects only direct child elements (elements directly underneath the first one) of the selector specified, so, in this case, only the one immediately underneath <code>#store</code>.</p> <p><code>#store + .shoppingCart { background-color: red; }</code></p> <pre><code>&lt;div class=shoppingCart&gt;This will not be targeted&lt;/div&gt; &lt;div id=store&gt; &lt;div class=shoppingCart&gt;This will not be targeted&lt;/div&gt; &lt;div class=shoppingCart&gt;This will not be targeted either&lt;/div&gt; &lt;div class=inner&gt; &lt;div class=shoppingCart&gt;This will not be targeted either&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=shoppingCart&gt;This WILL be targeted&lt;/div&gt; &lt;div class=shoppingCart&gt;But this one won't be&lt;/div&gt; </code></pre> <p>The <code>+</code> combinator selects an element that is the immediate next sibling (elements that are on the same level, ie. next to one another) of the first element, so if there is a <code>.shoppingCart</code> that is a sibling after a <code>#store</code>, it will be selected - but only if that element is AFTER the first one; a previous sibling cannot be selected in this way.</p> <p><code>#store ~ .shoppingCart { background-color: red; }</code></p> <pre><code>&lt;div class=shoppingCart&gt;This will not be targeted&lt;/div&gt; &lt;div id=store&gt; &lt;div class=shoppingCart&gt;This will not be targeted&lt;/div&gt; &lt;div class=shoppingCart&gt;This will not be targeted either&lt;/div&gt; &lt;div class=inner&gt; &lt;div class=shoppingCart&gt;This will not be targeted either&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=shoppingCart&gt;This WILL be targeted&lt;/div&gt; &lt;div class=shoppingCart&gt;This WILL be targeted as well&lt;/div&gt; </code></pre> <p>The <code>~</code> combinator selects an element that is any following sibling of the first element, so if there is a <code>.shoppingCart</code> that follows as a sibling of <code>#store</code>, it will be selected.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload