css有两大特性:继承性和层叠性

继承性

继承:给父级设置一些属性,子级继承了父级的该属性,这就是我们的css中的继承。

记住:有一些属性是可以继承下来 : color 、 font-*、 text-*、line-* 。主要是文本级的标签元素。

但是像一些盒子元素属性,定位的元素(浮动,绝对定位,固定定位)不能继承

有一些属性不能被继承,如:border, margin, padding, background等。

 

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
    <style type="text/css">
        .father{
            color: red;
        }
    </style>
</head>
<body>
    <!--
       继承:给父级设置一些属性,子级继承了父级的该属性,这就是我们的css中的继承。
       记住:有一些属性是可以继承下来 : color 、 font-*、 text-*、line-* 。主要是文本级的标签元素。
        
       但是像一些盒子元素属性,定位的元素(浮动,绝对定位,固定定位)不能继承。
    -->
    <div class="father" id="user">
        <p>mike</p>
    </div>
</body>
</html>

 

 

前端 CSS的继承性

inherited from 继承

 前端 CSS的继承性

 

 

前端 CSS的继承性

 

 

前端 CSS的继承性

 

 

前端 CSS的继承性

 

相关文章:

  • 2022-02-14
  • 2022-12-23
  • 2021-11-28
  • 2021-05-07
  • 2022-12-23
  • 2021-12-17
  • 2021-11-03
  • 2021-07-19
猜你喜欢
  • 2021-05-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-14
  • 2021-11-04
相关资源
相似解决方案