In CSS, the symbols you mention are:
>
is the the child combinator;
+
is the adjacent sibling combinator;
~
is the general sibling combinator.
The difference between them is this:
#store > .shoppingCart { background-color: red; }
<div class=shoppingCart>This will not be targeted</div>
<div id=store>
<div class=shoppingCart>This WILL be targeted</div>
<div class=shoppingCart>This WILL ALSO be targeted</div>
<div class=inner>
<div class=shoppingCart>This will not be targeted</div>
</div>
</div>
<div class=shoppingCart>This will not be targeted either</div>
<div class=shoppingCart>Neither will this</div>
The >
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 #store
.
#store + .shoppingCart { background-color: red; }
<div class=shoppingCart>This will not be targeted</div>
<div id=store>
<div class=shoppingCart>This will not be targeted</div>
<div class=shoppingCart>This will not be targeted either</div>
<div class=inner>
<div class=shoppingCart>This will not be targeted either</div>
</div>
</div>
<div class=shoppingCart>This WILL be targeted</div>
<div class=shoppingCart>But this one won't be</div>
The +
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 .shoppingCart
that is a sibling after a #store
, it will be selected - but only if that element is AFTER the first one; a previous sibling cannot be selected in this way.
#store ~ .shoppingCart { background-color: red; }
<div class=shoppingCart>This will not be targeted</div>
<div id=store>
<div class=shoppingCart>This will not be targeted</div>
<div class=shoppingCart>This will not be targeted either</div>
<div class=inner>
<div class=shoppingCart>This will not be targeted either</div>
</div>
</div>
<div class=shoppingCart>This WILL be targeted</div>
<div class=shoppingCart>This WILL be targeted as well</div>
The ~
combinator selects an element that is any following sibling of the first element, so if there is a .shoppingCart
that follows as a sibling of #store
, it will be selected.