zoukankan      html  css  js  c++  java
  • CSS Inheritance

     

    HTML elements can inherit CSS styles from their parent elements. This is called CSS inheritance. Here is a CSS inheritance example:

    <div>
        <p>
            This text inherits the font-size of the parent div element.
        </p>
    </div>    
    <style>
        div {
            font-family: Aial;
        }
    </style>    
    

    In this example the div element has the font-family property set to Arial. This CSS property is inherited by the nested p element, so it will also have its CSS property font-family set to Arial.

    HTML elements can inherit styles from more remote ancestors too, and not just from their parents. Look at this example:

    <body>
        <div>
            <p>
                This text inherits the font-size of the parent div element.
            </p>
        </div>    
        <style>
            body {
                font-family: Aial;
            }
        </style>
    </body>    
    

    In this example the CSS property font-family is set on the body element. This CSS property is then inherited by the div and p elements.

    Not all styles are inherited from a parent or ancestor element. Generally, styles that apply to text are inherited, whereas borders, margins and paddings and similar styles are not.

  • 相关阅读:
    python-常用数据类型
    python入门篇
    Vue 架构
    Bootstrap Web框架
    策略模式
    Java线程安全总结
    JVM中线程状态转换图
    java 多线程并发系列之 生产者消费者模式的两种实现
    JVM 垃圾回收器详解
    MyISAM和InnoDB索引实现对比
  • 原文地址:https://www.cnblogs.com/hephec/p/4563334.html
Copyright © 2011-2022 走看看