Advertisement

CSS的margin属性是什么?在嵌套布局中为何子元素设置会影响父元素

阅读量:

我们以下面的代码为例:

html代码:

复制代码
 <body>

    
 <div class="box1">
    
 <div class="box2"></div>
    
 </div>
    
 </body>

css代码:

复制代码
     <style>

    
     .box1{
    
         width: 300px;
    
         height: 300px;
    
         background-color: red;
    
     }
    
     .box2{
    
         width: 100px;
    
         height: 100px;
    
         background-color: blue;
    
         margin:0 auto;
    
         margin-top:100px;
    
     }
    
     </style>

展示结果:

全部评论 (0)

还没有任何评论哟~