Is there any advantage in having * + in CSS?

I know it's an example to explain but can I confirm that:

* + fieldset {margin: 5em, ...}


Would be the same as:

fieldset {margin: 5em, ...}


Thanks!



Link to content: CSS Master, 3rd Edition - Section 1

I’m not a CSS expert, but I think you’ll find the answer is no. The plus sign is an Adjacent sibling selector. It selects a following element next to the element on the left side of the plus sign.

It might be easier to grasp with an example. Say we use the following selector * + p

<div>
  <p>Paragraph 1<p> /* Not Selected!: This is the first element and isn't next to 'any' element */
  <p>Paragraph 2<p> /* Selected: This is next to an 'any' element -> paragraph 1 */
  <p>Paragraph 3<p> /* Selected: This is next to an 'any' element -> paragraph 2 */
</div>

I’m sure someone more qualified can better explain :slight_smile:

1 Like

Ah thank you. So it only works in one direction! that makes sense

1 Like