码迷,mamicode.com
首页 > 其他好文 > 详细

margin外边距问题

时间:2015-08-01 17:00:03      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

1 、上下边距会叠加

  1. !DOCTYPE html>
    <html>
    <head>
    <m<etacharset="UTF-8">
    <title></title>
    <style>
    .box1{
    width:500px;
    height:300px;
    background: blue;
    margin-bottom:30px;
    }
    .box2{
    width:300px;
    height:100px;
    background:#ffff00;
    margin-top:30px;
    }
    </style>
    </head>
    <body>
    <divclass="box1"></div>
    <divclass="box2"></div>
    </body>
    </html>

    技术分享

2、父级包含子级的时候,子级的margin-top会传递给父级,可以使用父级的padding替代自己的margin。
  1. <!DOCTYPE html>
    <html>
    <head>
    <metacharset="UTF-8">
    <title></title>
    <style>
    .box1{
    width:500px;
    height:300px;
    background: blue;
    }
    .box2{
    width:300px;
    height:100px;
    background:#ffff00;
    margin-top:30px;
    }
    </style>
    </head>
    <body>
    <divclass="box1">
    <divclass="box2"></div>
    </div>
    </body>
    </html>

    技术分享

3、margin左右
margin-lefta:uto     偏右
margin-right:auto       偏左
margin:auto      水平居中
 
    

margin外边距问题

标签:

原文地址:http://www.cnblogs.com/staven/p/4694186.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!