Nested Affinity Selectors in LESS

Let's look at how to add different selectors in LESS when nesting, selecting elements by relationship. See examples.

Example

Child selector:

styles.lessdiv {
  > p {
    color: red;
  }
}

Compilation result:

styles.cssdiv > p {

}

Example

Neighbor selector

styles.lessdiv {
  + p {
    color: red;
  }
}

Compilation result:

styles.cssdiv + p {

}

Example

Related selector:

styles.lessdiv {
  ~ p {
    color: red;
  }
}

Compilation result:

styles.cssdiv ~ p {

}

Practical tasks

Задание 1

Tell me what the result of compiling the following code will be:

styles.lessul {
  color: red;
  
  > li {
    padding: 20px;
  }
}
Задание 2

Tell me what the result of compiling the following code will be:

styles.lessdiv {
  ul {
    > li {
      padding: 20px;
    }
  }
}