1、背景属性复习: background-image background-color background-repeat background-position background-attachment

2、新增属性: background-size: background-size:x y;   // 水平 垂直方向的尺寸,像素/百分比/auto/⋯ background-size:cover;  //保持宽高比不变,保证占满盒子,但不保证能看到全部 background-size:contain; //保持宽高比不变,保证看清全图,但可能占不满盒子

多背景: background-image:url(1.jpg),url(2.jpg);

background-origin  背景区域定位      border-box: 从border区域开始显示背景   padding-box: 从padding区域开始显示背景   content-box: 从content内容区域开始显示背景

background-clip 背景绘制区域   border-box: 从border区域开始绘制背景   padding-box: 从padding区域开始绘制背景   content-box: 从content内容区域开始显示背景

3、背景练习:

<!DOCTYPE HTML>
<html>
  <head>
    <title>your title name</title>
    <meta charset="utf-8">
    <meta name="Author" content="Wilson Xu">
    <style type="text/css">
      *{margin: 0;padding: 0;font-family: "Microsoft yahei";}
      a{text-decoration: none;}
      a img{display: block;border: none;}
      li{list-style: none;}
 
      .container{
        width: 1200px;
        padding: 20px;
        margin: 10px auto;
        border: 1px dashed #ccc;
      }
      .container h4{padding-bottom: 5px;}
      .container ul{
        width: 1200px;
        overflow: hidden;
      }
      .container ul li{
        float: left;
        width: 331px;
        padding: 20px;
        height: 240px;
        margin-right: 10px;
        border: 10px solid rgba(10,10,10,.3);
        background: url('images/1.jpg') no-repeat;
        background-size: 371px auto;
      }
      .container ul li:last-child{margin-right: 0;}
 
      .container ul.origin li:nth-child(1){
        background-origin: border-box;
      }
      .container ul.origin li:nth-child(2){
        background-origin: padding-box;
      }
      .container ul.origin li:nth-child(3){
        background-origin: content-box;
      }
 
      .container ul.clip li:nth-child(1){
        background-clip: border-box;
      }
      .container ul.clip li:nth-child(2){
        background-clip: padding-box;
      }
      .container ul.clip li:nth-child(3){
        background-clip: content-box;
      }
 
      section .pic{
        width: 600px;
        height: 400px;
        margin: 20px auto;
        border: 1px dashed #ddd;
        background: url('images/3.jpg') no-repeat center center/auto 200px, url('images/2.jpg') no-repeat center center/auto 300px, url('images/1.jpg') no-repeat center center/auto 400px;
      }
      section p{
        font-size: 14px;
        color: #f01010;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <section>
        <h4>1、background-origin: border-box | padding-box | content-box</h4>
        <ul class="origin">
          <li></li>
          <li></li>
          <li></li>
        </ul>
      </section>
      <section>
        <h4 style="margin-top: 20px;border-top: 1px dashed #ccc;">2、background-clip: border-box | padding-box | content-box</h4>
        <ul class="clip">
          <li></li>
          <li></li>
          <li></li>
        </ul>
      </section>
      <section>
        <h4 style="margin-top: 20px;border-top: 1px dashed #ccc;">3、多背景:background: url('images/3.jpg') no-repeat center center/auto 200px, url('images/2.jpg') no-repeat center center/auto 300px, url('images/1.jpg') no-repeat center center/auto 400px;
</h4>
        <div class="pic"></div>
        <p>注释:复合写background-size的时候,一定要用/与其他值隔开。</p>
      </section>
    </div>
  </body>

</html>

练习代码部分:

最新文章

  1. 基于AngularJS的个推前端云组件探秘
  2. 自动化脚本过程中出现This element neither has attached source nor attached Javadoc...的解决方法
  3. 适合于小团队产品迭代的APP测试流程
  4. HDU 4588 Count The Carries(找规律,模拟)
  5. 【转】浅析linux内存模型
  6. Ubuntu修改屏幕默认亮度
  7. android 中在CMD中查看sqlite
  8. VS2015升级Update2之后Cordova程序提示:此应用程序无法在此电脑上运行
  9. 十一、C# 泛型
  10. ganglia Web前端清除当机节点
  11. (Sql Server)数据的拆分和合并
  12. .NET框架设计—常被忽视的C#设计技巧
  13. 在nltk中调用stanfordparser处理中文
  14. 一个php技术栈后端猿的知识储备大纲
  15. 【zabbix教程系列】六、自动注册(Linux)
  16. 【视频】使用ASP.NET Core开发GraphQL服务
  17. Vmware12安装centos系统详解
  18. 初识DMA
  19. 【洛谷4070】 [SDOI2016]生成魔咒(SAM)
  20. python之numpy.power()数组元素求n次方

热门文章

  1. pigofzhou的巧克力棒
  2. vue中eventbus的使用
  3. window.location.href和window.top.location.href的区别
  4. js003-4方向8方向函数
  5. 【Henu ACM Round#18 E】Anya and Cubes
  6. Android实现本地图片选择及预览缩放效果仿春雨医生
  7. vim 常用插件功能跟配置
  8. jQuery简单tab按钮切换
  9. hostname---显示和设置系统的主机
  10. WPF框架ZFS