Select each item after the item except the first child

I would like to compile the following LESS rule: - every element after the current element except the first child

It should look something like this:

(& ~ *):not(:first-child) {
  margin-left: 5px;
}

or that:

& ~ *:not(:first-child) {
  margin-left: 5px;
}

Unfortunately, both do not work.

+4
source share
1 answer

The class pseudo-class :first-childalways refers to the first child of its parent. It cannot be used to ignore the first child element (sibling) following the reference element.

If you want to select all elements except the first element that follows the reference element, then it should be written as follows:

.reference + * ~ *{
  color: red;
}

.reference , + * , ~ * .

(), , :

.reference {
  & + * ~ * {
    color: red;
    /* and any other rules */
  }
}

.

.reference + * ~ *{
  color: red;
}
<div class='reference'>Reference Element</div>
<p>Some other element which is the first one after reference element</p>
<div>The elements to be selected</div>
<p>The element to be selected</p>
+7

Source: https://habr.com/ru/post/1623766/


All Articles