CSS 中 margin 属性(值为 Inherit)的作用

cssweb developmentfront end technology更新于 2024/4/3 5:32:17

margin 属性(值为 Inherit)用于从父元素继承元素。您可以尝试运行以下代码来实现 margin: Inherit;

示例

<!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>

输出


相关文章


有用资源