第二十三章 背景相关

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>背景</title>
    <style media="screen">
    *{
      margin: 0;
      padding: 0;
    }

    /*ul{
      width: 800px;
      height: 1200px;
      margin:100px auto;
    }
    li {
      list-style: none;
      width: 200px;
      height: 200px;
      float: left;
      margin:30px;
      border: 1px solid;
      text-align: center;
      line-height: 200px;
    }
    ul li:nth-child(1){
      background: url("../image/o.gif") no-repeat;
    }
    ul li:nth-child(2){
      background: url("../image/o.gif") no-repeat;
      background-size: 100px 80px;
    }
    ul li:nth-child(3){
      background: url("../image/o.gif") no-repeat;
      background-size: 50% 60%;
    }
    ul li:nth-child(4){
      background: url("../image/o.gif") no-repeat;
      background-size: auto 50%;
    }
    ul li:nth-child(5){
      background: url("../image/o.gif") no-repeat;
      background-size: 60% auto;
    }
    ul li:nth-child(6){
      background: url("../image/o.gif") no-repeat;
      background-size: cover;
    }
    ul li:nth-child(7){
      background: url("../image/o.gif") no-repeat;
      background-size: contain;
    }*/

    /*li{
      width: 100px;
      height: 100px;
      text-align: center;
      line-height: 100px;
      border: 20px dashed;
      padding: 50px;
      margin-left: 20px;
      background: url("../image/o.gif") no-repeat;
      float: left;
    }
    ul li:nth-child(2){
      background-origin: padding-box;
    }
    ul li:nth-child(3){
      background-origin: border-box;
    }
    ul li:nth-child(4){
      background-origin: content-box;
    }*/

    /*li{
      width: 100px;
      height: 100px;
      text-align: center;
      line-height: 100px;
      border: 20px dashed;
      padding: 50px;
      margin-left: 20px;
      background: red url("../image/o.gif") no-repeat;
      float: left;
    }
    ul li:nth-child(2){
      background-clip: padding-box;
    }
    ul li:nth-child(3){
      background-clip: border-box;
    }
    ul li:nth-child(4){
      background-clip: content-box;
    }*/

    /*div {
      width: 500px;
      height: 500px;
      border: 1px solid;
      margin: 100px auto;
      background:url("../image/o.gif") no-repeat left top,
                url("../image/call.jpeg") no-repeat right top;

      background-image: url("../image/o.gif"),url("../image/call.jpeg");
      background-repeat: no-repeat;
      background-position: left top, right top;
    }*/

    div{
      width: 600px;
      height: 190px;
      border: 1px solid;
      margin: 100px auto;
      background-image: url("../image/call.jpeg"),url("../image/call.jpeg"),url("../image/o.gif");
      background-repeat: no-repeat;
      background-size: 50px 50px, 50px 50px, 2000px 190px;
      background-position: 50px 150px,400px 50px, 0px 0px;

      animation: move 10s linear 0s infinite normal;
    }
    @keyframes move {
      from{
        background-position: 50px 50px, 400px 50px, 0px 0px;
      }
      to{
        background-position: 500px -150px, 400px 50px, -600px 0px;
      }
    }
    </style>
  </head>
  <body>
    <!-- <ul>
      <li>默认</li>
      <li>具体像素</li>
      <li>百分比</li>
      <li>宽度等比例拉伸</li>
      <li>高度等比例拉伸</li>
      <li>cover</li>
      <li>contain</li>
    </ul> -->

    <!-- <ul>
      <li>默认</li>
      <li>padding</li>
      <li>border</li>
      <li>content</li>
    </ul> -->

    <div class="">

    </div>
  </body>
</html>

第187课 背景尺寸属性

背景尺寸属性就是CSS3中新增的一个属性,专门用于设置背景图片大小

默认:图片按照自己的尺寸复制填满整个元素

background-image: url("../image/o.gif");

具体像素:图片根据设置的像素显示

background-size: 100px 80px;

百分比:图片根据元素的尺寸的百分比显示

background-size: 50% 60%;

宽度等比例拉伸:图片根据设定的高度等比例拉伸显示

background-size: auto 50%;

高度等比例拉伸:图片根据设定的宽度等比例拉伸显示

background-size: 60% auto;

cover:图片等比例拉伸,并且直到宽度高度都填满整个元素为止显示

background-size: cover;

contain:图片等比例拉伸,直到宽度或高度有一个填满元素为止显示

background-size: contain;

第188课 背景图片定位区域属性

告诉系统背景图片从什么区域开始显示,
默认情况下从padding区域开始显示

background-origin: padding-box;
background-origin: border-box;
background-origin: content-box;

第189课 背景绘制区域属性

背景绘制区域属性是专门用于指定从哪个区域开始绘制背景,
默认情况下会从border区域开始绘制背景

background-clip: border-box;
background-clip: padding-box;
background-clip: content-box;

第190课 多重背景图片

多张背景图片之间用逗号隔开即可

background:url("../image/o.gif") no-repeat left top,
url("../image/call.jpeg") no-repeat right top;

注意点

先添加的背景图片会盖住后添加的背景图片

建议在编写多重背景时拆开编写

background-image: url("../image/o.gif"),url("../image/call.jpeg");
background-repeat: no-repeat;
background-position: left top, right top;

第191课 多重背景图片练习

练习看代码

最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    wzhiq896阅读 2,204评论 0赞 2
  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    love2013阅读 2,492评论 0赞 11
  • background-color background-color:#ff0000红色background-col...
    每日活菌阅读 581评论 0赞 0
  • background应该是CSS里使用频率颇高的属性,简单实用。但参数偏多,本篇就介绍一下background的各...
    张歆琳阅读 4,484评论 4赞 26
  • 一. 背景尺寸属性 1.什么是背景尺寸属性背景尺寸属性是CSS3中新增的一个属性, 专门用于设置背景图片大小 ba...
    壹点微尘阅读 362评论 0赞 0

友情链接更多精彩内容