Role of margin property with value inherit using CSS


The margin property with value inherit is used to inherit an element from the parent element. You can try to run the following code to implement margin: inherit;

Example

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            border: 2px solid blue;
            margin-left: 50px;
         }
         p.ex1 {
            margin-left: inherit;
         }
      </style>
   </head>
   <body>
      <p>Inheriting left margin from the parent element</p>
      <div>
         <p class = "ex1">This is demo text with inherited left margin.</p>
      </div>
   </body>
</html>

Output

Updated on: 22-Jun-2020

283 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements