如何理解css普通兄弟选择器

1、CSS普通兄弟选择器是指所有连接到另一个元素的元素,两者都有相同的父元素。

2、普通兄弟选择器使用波浪号(~)作为普通兄弟的结合符。

实例

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>普通兄弟选择器</title>
  <style>
    .ancestor {
      width: 500px;
      height: 300px;
    }
    .parent {
      width: 300px;
      height: 200px;
    }
    .child {
      width: 200px;
      height: 100px;
    }
    /* 定位的是 .child1 的后面兄弟为 div 的元素 */
    .child1~div {
      background-color: lightcoral;
    }
  </style>
</head>
<body>
  <div>
    this is ancestor.
    <div>
      this is parent.
      <div>this is child0.</div>
      <div>this is child1.</div>
      <div>this is child2.</div>
      <div>this is child3.</div>
    </div>
  </div>
</body>
</html>

1、缩进用四个空格。2、在每个声明块的左花括号之前添加一个空格。3、声明块的右花括号应单独设置。4、每个声明语句:之后插入一个空格,前面没有空格。5、所有的声明句子都以分号结束,不能省略不写。实例/* bad */.mod- ...