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 p >5、背景練習preview:
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、漸變練習代碼部分:
!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: 20px auto; border: 1px dashed #ccc; .container h4{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); /style /head body p >8、漸變preview:
以上就是實例詳解Html5的背景應用的詳細內容,html教程
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答