css入门6: 分组和嵌套

分组定义相同属性,如:

    h1,h2,h3{
      color: blue;
    }


嵌套,如:

p.marked
{
color:white;
}

p.marked类只能在p中起作用,在div或者其他标签中不起作用。


举个栗子,

<html>

<head>
  <style>
    h1,
    h2,
    h3 {
      color: blue;
    }

    p.marked {
      color: red;
    }
  </style>
</head>

<body>

  <!-- 分组定义相同属性 -->
  <h1>hello</h1>
  <h2>hello</h2>
  <h3>hello</h3>

  <!-- 嵌套的类p.marked,只有在p中起作用,在div中不起作用 -->
  <p class="marked">
    This is a paragraph;
  </p>

  <div class="marked">
    this is a div
  </div>

</body>


</html>


猜你喜欢

转载自blog.csdn.net/inch2006/article/details/80431525