What does the inherit keyword in CSS do?

前端 未结 1 453
自闭症患者
自闭症患者 2021-01-03 22:05

Can somebody please explain, what is the inherit keyword meant to do in CSS?

相关标签:
1条回答
  • 2021-01-03 22:49

    It will use the same value as the same property his parent has.

    html:

    <body>
    <h1></h1>
    </body>
    

    css:

    body{
     margin: 234px;
    }
    h1{
     margin: inherit; #=234px
    }
    

    Note to this if there are multiple instances of <h1> in the file, it will take the margin of it's parent. So 234px is not always the value it will have. For example

    html:

    <body>
      <h2></h2>
      <div>
        <h2></h2>
      </div>
    </body>
    

    css:

    body{
    margin: 20px;
    }
    div{
    margin: 30px;
    }
    h2{
    margin: inherit; #20px if parent is body; 30px if parent is div
    }
    
    0 讨论(0)
提交回复
热议问题