品易云推流 关闭
文章详情页
文章 > css教程 > css普通兄弟选择器如何理解

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

css 普通兄弟选择器

头像

小妮浅浅

2021-10-23 19:10:176253浏览 · 0收藏 · 0评论

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教程

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图