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

218次阅读
没有评论

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>

以上就是css普通兄弟选择器的理解,希望对大家有所帮助。更多css学习指路:css教程

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:JavaScript2022-12-19发表,共计775字。
新手QQ群:570568346,欢迎进群讨论 Python51学习