[Web 前端] 013 css 内外边距

1. css 内间距

  • 也称:“内补白”或“内补丁”
参数释义
padding检索或设置对象四边的内部边距,如 padding:10px; padding:5px 10px;
padding-top检索或设置对象顶边的内部边距
padding-right检索或设置对象右边的内部边距
padding-bottom检索或设置对象下边的内部边距
padding-left检索或设置对象左边的内部边距
  • 举例
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>test</title>
        <link rel="stylesheet" type="text/css" href="./static/CSS/test.css">
    </head>
    <body>
        <div class="box1">box1</div>
        <div class="box2">box2</div>
        <div class="box3">box3</div>
        <div class="box4">box4</div>
    </body>
</html>
*{
    width: 100px;
    height: 100px;
}
.box1{
    background-color: #edd094;
}
.box2{
    background-color: #a7ab86;
    padding-top: 10px;
    padding-bottom: 10px;
    padding-left: 10px;
    padding-right: 10px;
}
.box3{
    background-color: #b35e59;
    padding: 10px;
}
.box4{
    background-color: #8a7e94;
    padding: 10px 15px;
}
  • 效果

1576387-20190502112129038-1271036293.png

2. css 外间距

  • 也称:“外补白”或“外补丁”
参数释义
margin检索或设置对象四边的外延边距,如 margin:10px; margin:5px auto;
margin-top检索或设置对象顶边的外延边距
margin-right检索或设置对象右边的外延边距
margin-bottom检索或设置对象下边的外延边距
margin-left检索或设置对象左边的外延边距
  • 举例
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>test</title>>
        <link rel="stylesheet" type="text/css" href="./static/CSS/test.css">
    </head>
    <body>
        <div class="box1">box1</div>
        <div class="box2">box2</div>
        <div class="box3">box3</div>
        <div class="box4">box4</div>
    </body>
</html>
*{
    width: 100px;
    height: 100px;
}
.box1{
    background-color: #edd094;
}
.box2{
    background-color: #a7ab86;
    margin-top: -10px;
    margin-bottom: 10px;
    margin-left: 10px;
    margin-right: 10px;
}
.box3{
    background-color: #b35e59;
    margin: 10px;
}
.box4{
    background-color: #8a7e94;
    margin: 10px 20px;
}
.box5{
    background-color: #f1c4be;
    margin: 10px auto;
}
  • 效果截图

1576387-20190502112710959-82900959.png

margin 相关技巧

  1. 设置元素水平居中:margin:x auto;
  2. margin 负值让元素位移及边框合并

转载于:https://www.cnblogs.com/yorkyu/p/10801904.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值