今天推荐一个有关于Background的多背景使用——CSS3 Multipls Backgrounds。
background: background-color || background-image || background-repeat || background-attachment || background-position; 也可以分解写成: background-color: color值 || RGBA值; background-image: url(); background-repeat: repeat || repeat-x || repeat-y || no-repeat; background-attachment: scroll || fixed; background-position: <length> || <per>
background: background-image || background-position/background-size || background-repeat || background-attachment || background-clip || background-origin || background-color 也可以分解写成: background-image: url(); background-position: <length> || <per> background-size: <length> || <per> background-repeat: repeat || repeat-x || repeat-y || no-repeat; background-attachment: scroll || fixed; background-clip: padding-box || border-box || content-box; background-origin: padding-box || border-box || content-box; background-color: color值 || RGBA值;
background: background-color || background-image || background-repeat || background-attachment || background-position; background-size: <length> || <per> background-clip: padding-box || border-box || content-box; background-origin: padding-box || border-box || content-box;
background-(position||repeat||clip||size||origin||attachment) background : [background-image] | [background-position][/background-size] | [background-repeat] | [background-attachment] | [background-clip] | [background-origin],* 也可以分解成: background-image: url1,url2,...,urlN; background-repeat: repeat1,repeat2,...,repeatN; background-position: position1,position2,...,positionN; background-size: size1,size2,...,sizeN; backrgound-attachment: attachment1,attachment2,...,attachmentN; background-clip: clip1,clip2,...,clipN; background-origin: origin1,origin2,...,originN; background-color: color;
需要完成的效果
<div class="box-wrp"> <div class="tl">左上角背景图</div> <div class="tr">右上角背景图</div> <div class="content">我使用了五张背景图片。制作这样的效果</div> <div class="bl">左下角背景图</div> <div class="br">右下角背景图</div> </div>
<div class="demo multipleBg">我使用了五张背景图片。制作这样的效果</div>
.demo { width: 240px; border: 20px solid rgba(104, 104, 142,0.5); -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; padding: 80px 60px; color: #f36; font-size: 25px; line-height: 1.5; text-align:center; } .multipleBg { background: url("../images/bg-tl.png") no-repeat left top,url("../images/bg-tr.png") no-repeat right top,url("../images/bg-bl.png") no-repeat left bottom,url("../images/bg-br.png") no-repeat right bottom,url("../images/bg-repeat.png") repeat left top; /*改变背景图片的position起始点,四朵花都是border边缘处起,而平铺背景是在paddin内边缘起*/ -webkit-background-origin: border-box, border-box,border-box,border-box,padding-box; -moz-background-origin: border-box, border-box,border-box,border-box,padding-box; -o-background-origin: border-box, border-box,border-box,border-box,padding-box; background-origin: border-box, border-box,border-box,border-box,padding-box; /*控制背景图片的显示区域,所有背景图片超边border外边缘都将被剪切掉*/ -moz-background-clip: border-box; -webkit-background-clip: border-box; -o-background-clip: border-box; background-clip: border-box; }
.multipleBg { background-attachment: scroll, scroll, scroll, scroll, scroll; -webkit-background-clip: border-box; -o-background-clip: border-box; background-clip: border-box; background-color: transparent; background-image: url("../images/bg-tl.png"), url("../images/bg-tr.png"), url("../images/bg-bl.png"), url("../images/bg-br.png"), url("../images/bg-repeat.png"); /*Firefox,Safari,Chrome早期版本支持background-origin语法格式*/ -moz-background-origin: border, border, border, border, padding; -webkit-background-origin: border, border, border, border, padding; /*Firefox,Safari,Chrome现代版本支持background-origin语法格式*/ -moz-background-origin: border-box, border-box, border-box, border-box, padding-box; -webkit-background-origin: border-box, border-box, border-box, border-box, padding-box; -o-background-origin: border-box, border-box, border-box, border-box, padding-box; background-origin: border-box, border-box, border-box, border-box, padding-box; background-position: left top, right top, left bottom, right bottom, left top; background-repeat: no-repeat, no-repeat, no-repeat, no-repeat, repeat; background-size: auto auto, auto auto, auto auto, auto auto, auto auto; }
HTML code
<div class="card bigToSmall"></div>
.card { border: 1px solid #ccc; padding: 10px; height:100px; width:120px; } .bigToSmall{ background-image: url("../images/nine.png"),url("../images/eight.png"),url("../images/seven.png"); background-position: 0 0pt, 15px 20px, 30px 40px; background-repeat: no-repeat; -moz-background-origin: content-box; -webkit-background-origin: content-box; -o-background-origin: content-box; background-origin: content-box; }