CSS Basics Tuto...LOGIN

CSS Basics Tutorial: Inheritance

CSS inheritance

CSS property inheritance: The style of the outer element will be inherited by the inner element. The styles of multiple outer elements will eventually be "overlaid" on the inner elements.

Example:

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
    <style type="text/css">
     div{
         color:red;
     }
     h1{
        color:blue; 
     }
     p{
         color:green;
     }
    </style>
    </head>
    <body>
        <div>
        <h1>习近平心中的互联网</h1>
        <p>互联网是20世纪最伟大的发明,它正在将人类“一网打尽”,人们在不知不觉中已经融入了互联网生态,互联网让世界变成了“鸡犬之声相闻”的地球村。
        </p>
        </div>
    </body>
</html>

View firebug locally and you can see

25.png


##What kind of CSS properties can be inherited?

CSS text properties will be inherited:

color, font-size, font-family, font-style, font-weight

text-align, text-decoration, text-indent, letter-spacing, line-height

Tip: The CSS properties in <body> will be inherited by all child elements.


Next Section

<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <style type="text/css"> div{ color:red; } h1{ color:blue; } p{ color:green; } </style> </head> <body> <div> <h1>习近平心中的互联网</h1> <p>互联网是20世纪最伟大的发明,它正在将人类“一网打尽”,人们在不知不觉中已经融入了互联网生态,互联网让世界变成了“鸡犬之声相闻”的地球村。 </p> </div> </body> </html>
submitReset Code
ChapterCourseware