前端 CSS的继承性

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>
扫描二维码关注公众号,回复: 6139326 查看本文章

inherited from 继承

 

猜你喜欢

转载自www.cnblogs.com/mingerlcm/p/10803192.html
今日推荐