父子关系的

html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <link rel="stylesheet" href="demo63.css">
  9. </head>
  10. <body>
  11. <div class="box">
  12. <p>12345678</p>
  13. </div>
  14. </body>
  15. </html>

less

.box {
  width: 200px;
  height: 200px;
  background-color: blue;

  p {
    color: red;
  }
}

less编译成的css

.box {
  width: 200px;
  height: 200px;
  background-color: blue;
}
.box p {
  color: red;
}

效果图

image.png

交集、伪类、伪元素选择器

如果遇见(交集|伪类|伪元素选择器)

  • 内层选择器的前面没有 &符号,则它被解析为父选择器的后代;
  • 如果有&符号 ,它就被解析为父元素自身或父元素的伪类。

    html

    ```html <!DOCTYPE html>

<a name="XcpcE"></a>
## less
```less
.box {
  width: 200px;
  height: 200px;
  background-color: blue;

  a {
    color: red;

    &::after {
      content: " very good!";
    }
  }
}

less编译成的css

.box {
  width: 200px;
  height: 200px;
  background-color: blue;
}
.box a {
  color: red;
}
.box a::after {
  content: " very good!";
}
c