css样式表基本属性2

外边距与内边距属性

1盒子简介

盒子模型如图所示:
![盒子模型](https://img-blog.csdn.net/20170506143357536?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMjUyNjY3NDM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)

2外边距

  1. 上边距margin-top:边距值
  2. 下边距margin-bottom:边距值
  3. 左边距margin-left:边距值
  4. 右边距margin-right:边距值
  5. 外边距复合属性margin
  语法:`margin:长度值|百分比|auto`
  取值说明:
  - 长度值为绝对边距值,包括数字和单位;
  - 百分比相对于上级元素宽度,允许负值;
  - auto自动取边距值,即元素默认值。
  margin:10px; 所有外边距都为10px;
  margin:10px 20px; 上下边距为10px,左右边距为20px;
  margin:50px 10px 20px; 上边距50px,左右边距10px,下边距20px;
  margin:50px 10px 20px 30px; 上边距50px,右边距10px,下边距20px,左边距30px;
  示例:
<!doctype html>
<html lang="en">
 <head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8">
  <title>使用css样式表</title>
  <style type="text/css">
    <!--
     .h1{
        margin-top:10pt;
        margin-right:30pt;
        margin-bottom:10pt;
        margin-left:20pt;
      }
      .h2{
        margin:10pt 30pt 10pt 20pt;
      }
    -->
  </style>
 </head>
 <body>
   <span class="h1">授人以鱼不如授人以渔</span>
   <span class="h2">授人以鱼不如授人以渔</span>
 </body>
 </html>   

3内边距

  1. 顶端内边距padding-top:间隔值
  2. 底端内边距padding-bottom:间隔值
  3. 左端内边距padding-left:间隔值
  4. 右端内边距padding-right:间隔值
  5. 内边距复合属性padding
  语法:`padding:长度值|百分比`
  取值说明:
  - 长度值为绝对边距值,包括数字和单位;
  - 百分比相对于上级元素宽度,不允许负值。
  示例:
<!doctype html>
<html lang="en">
 <head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8">
  <title>使用css样式表</title>
  <style type="text/css">
    <!--
     body{
        padding-top:10pt;
        padding-right:30pt;
        padding-bottom:10pt;
        padding-left:20pt;
      }
     /*或body{
        padding:10pt 30pt 10pt 20pt;
      }*/
    -->
  </style>
 </head>
 <body>
   <p>授人以鱼不如授人以渔</p>
 </body>
 </html>   

4边框属性

边框有三个属性:边框宽度属性、边框颜色属性、边框样式。
  1. 边框样式border-style
     语法:border-style:样式值
          border-top-style:样式值
          border-right-style:样式值
          border-bottom-style:样式值
          border-left-style:样式值
     取值说明:none   默认,无边框
                     dotted 点线边框
                     dashed 虚线边框
                     solid 实线边框
                     double 双实线边框
                     groove 边框具有立体感的沟槽
                     ridge 边框成脊形
                     inset 边框凹陷,即边框内嵌入一个立体边框
                     outset 边框凸起,即边框外嵌入一个立体边框
     示例:
<!doctype html>
<html lang="en">
 <head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8">
  <title>使用css样式表</title>
  <style type="text/css">
    <!--
      .h{
        border-top-style:dashed;
        border-right-style:dashed;
        border-bottom-style:dotted;
        border-left-style:solid;
        line-height:20px;
      }
    -->
  </style>
 </head>
 <body>
   <span class="h">授人以鱼不如授人以渔</span>
 </body>
 </html>   
  2. 边框宽度border-width
     语法:border-width:宽度值
          border-top-width:宽度值
          border-right-width:宽度值
          border-bottom-width:宽度值
          border-left-width:宽度值
     取值说明:medium  默认宽度
              thin 小于默认宽度
              thick 大于默认宽度
<!doctype html>
<html lang="en">
 <head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8">
  <title>使用css样式表</title>
  <style type="text/css">
    <!--
      .h{
        border-top-style:dashed;
        border-right-style:dashed;
        border-bottom-style:dotted;
        border-left-style:solid;
        line-height:20px;
        border-top-width:2px;
        border-right-width:2px;
        border-bottom-width:2px;
        border-left-width:2px;
      }
    -->
  </style>
 </head>
 <body>
   <span class="h">授人以鱼不如授人以渔</span>
 </body>
 </html>    
  3. 边框颜色border-color
     语法:border-color:颜色值
          border-top-color:颜色值
          border-right-color:颜色值
          border-bottom-color:颜色值
          border-left-color:颜色值
     示例:
<!doctype html>
<html lang="en">
 <head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8">
  <title>使用css样式表</title>
  <style type="text/css">
    <!--
      .h{
        border-top-style:dashed;
        border-right-style:dashed;
        border-bottom-style:dotted;
        border-left-style:solid;
        line-height:20px;
        border-top-width:2px;
        border-right-width:2px;
        border-bottom-width:2px;
        border-left-width:2px;
        border-top-color:#ff9900;
        border-right-color:#0099ff;
        border-bottom-color:#cc33ff;
        border-left-color:#ccfffff;
      }
    -->
  </style>
 </head>
 <body>
   <span class="h">授人以鱼不如授人以渔</span>
 </body>
 </html>   
 4. 边框属性border
    语法:border: 边框宽度 样式 颜色值
         border-top: 上边框宽度 样式 颜色值
         border-right: 右边框宽度 样式 颜色值
         border-bottom: 下边框宽度 样式 颜色值
         border-left: 左边框宽度 样式 颜色值
    示例:
<!doctype html>
<html lang="en">
 <head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8">
  <title>使用css样式表</title>
  <style type="text/css">
    <!--
      .h{
        line-height:20px;
        font-family:"宋体";
        font-size:12px;
        border-top:2px dashed #00ccff;
        border-right:2px solid #3300ff;
        border-bottom:2px dotted #ff0000;
        border-left:2px solid #3300ff;
      }
    -->
  </style>
 </head>
 <body>
   <span class="h">授人以鱼不如授人以渔</span>
 </body>
 </html>   
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值