资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Html5中背景属性的示例分析-创新互联

这篇文章将为大家详细讲解有关Html5中背景属性的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

我们拥有十多年网页设计和网站建设经验,从网站策划到网站制作,我们的网页设计师为您提供的解决方案。为企业提供成都网站设计、成都网站建设、微信开发、微信小程序定制开发成都手机网站制作html5、等业务。无论您有什么样的网站设计或者设计方案要求,我们都将富于创造性的提供专业设计服务并满足您的需求。

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、背景练习代码部分:



  
    your title name
    
    
    
      *{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 h5{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;
      }
    
  
  
    
      
        
1、background-origin: border-box | padding-box | content-box
                   
  •           
  •           
  •                
          
            2、background-clip: border-box | padding-box | content-box                    
  •           
  •           
  •                
          
            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;         

            

    注释:复合写background-size的时候,一定要用/与其他值隔开。

          
        

      

    5、背景练习preview:

    Html5中背景属性的示例分析

    Html5中背景属性的示例分析



    6、渐变:

    线性渐变:linear-gradient(方位(left/left top/60deg),起始颜色 | 百分比30%,终止颜色);使用时加内核前缀eg:-webkit-linear-gradient,IE9不支持
    径向渐变:radial-gradient(中心点位置,扩散程度,颜色域 | 百分比);由中心向四周发散,eg:-webkit-radial-gradient(50px 50px,起始颜色,终止颜色);-webkit-radial-gradient(center,起始颜色,终止颜色);
    IE低版本兼容:filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff',endColorstr='#ff0000',GradientType='1');1表示从左到右,0是从上到下,并且颜色值只能是6位哈希值


    7、渐变练习代码部分:

    
    
      
        your title name
        
        
        
          *{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: 20px auto;
            border: 1px dashed #ccc;
          }
          .container h5{padding-bottom: 5px;}
          .container ul{
            width: 1200px;
            overflow: hidden;
          }
          .container ul.linear li,
          .container ul.filter li{
            width: 600px;
            height: 40px;
            margin: 10px 0;
          }
          .container ul.linear li:first-child{
            background: -webkit-linear-gradient(60deg,#fff 10%, #f00 30%, #0f0 50%, #00f 70%, #000);
          }
          .container ul.linear li:last-child{
            background: -webkit-linear-gradient(left top, rgba(122,156,233,.6) 30%, rgb(255,12,222) 60%, green 80%, #fff);
          }
          .container ul.filter li:first-child{
            background: filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#abcdef',endColorstr='#f44add',GradientType='0');
          }
          .container ul.filter li:last-child{
            background: filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff',endColorstr='#000000',GradientType='1');
          }
    
          .container ul.radial li{
            width: 200px;
            height: 200px;
            margin-right: 20px;
            float: left;
            border-radius: 100%;
          }
          .container ul.radial li:nth-child(1){
            background: -webkit-radial-gradient(center, #fff, #000);
          }
          .container ul.radial li:nth-child(2){
            background: -webkit-radial-gradient(left 50px, #fff, #000);
          }
          .container ul.radial li:nth-child(3){
            background: -webkit-radial-gradient(50px 100px,100px 100px, #fff 80%, #000);
          }
          .container ul.radial li:nth-child(4){
            background: -webkit-radial-gradient(left, #fff 20%, #f00 40%, #0f0 60%, #00f 80%, #000);
          }
        
      
      
        
          
            
    1、线性渐变:-webkit-linear-gradient(方位,颜色域 | 范围百分比)
                       
  •           
  •                
          
            
    2、线性渐变-兼容IE低版本:filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='6位哈希值',endColorstr='6位哈希值',GradientType='1/0');
                       
  •           
  •                
          
            
    3、径向渐变:radial-gradient(中心点位置,扩散程度,颜色域 | 百分比);
                       
  •           
  •           
  •           
  •                
        

      

    8、渐变preview:

    Html5中背景属性的示例分析

    关于“Html5中背景属性的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

    另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


    分享名称:Html5中背景属性的示例分析-创新互联
    文章分享:http://cdkjz.cn/article/gdspo.html
    多年建站经验

    多一份参考,总有益处

    联系快上网,免费获得专属《策划方案》及报价

    咨询相关问题或预约面谈,可以通过以下方式与我们联系

    大客户专线   成都:13518219792   座机:028-86922220