background-origin

设置元素背景图片的原始起始位置

语法:

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

参数分别表示背景图片是从边框,还是内边距(默认值),或者是内容区域开始显示。

效果如下:

需要注意的是,如果背景不是no-repeat,这个属性无效,它会从边框开始显示。

例子:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>背景原点</title>
<style type="text/css">
.wrap {
width:220px;
border:20px dashed #000;
padding:20px;
font-weight:bold;
color:#000;
background:#ccc url(http://static.mukewang.com/static/img/logo_index.png) no-repeat;
background-origin:content-box;//内容区域显示
position: relative;
}
.wrap span {
position: absolute;
left:0;
top:0;
}
.content {
height:80px;
border:1px solid #333;
}
</style>
</head>
<body>
<div class="wrap"><span>padding</span>
<div class="content">content</div>
</div>
</body>
</html>

效果:

background-clip

用来将背景图片做适当的裁剪以适应实际需要。

语法:

background-clip : border-box | padding-box | content-box | no-clip

参数分别表示从边框、内填充,或者内容区域向外裁剪背景。no-clip表示不裁切,和参数border-box显示同样的效果。backgroud-clip默认值为border-box

效果如下图所示:

例子:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>背景裁切</title>
<style type="text/css">
.wrap {
width:220px;
border:20px dashed #000;
padding:20px;
font-weight:bold;
color:#000;
background:#ccc url(http://static.mukewang.com/static/img/logo_index.png) no-repeat;
background-origin: border-box;
background-clip:padding-box;
position: relative;
}
.wrap span {
position: absolute;
left:0;
top:0;
}
.content {
height:80px;
border:1px solid #333;
}
</style>
</head>
<body>
<div class="wrap"><span>padding</span>
<div class="content">content</div>
</div>
</body>
</html>

效果: padding-box效果:

background-size

设置背景图片的大小,以长度值百分比显示,还可以通过covercontain来对图片进行伸缩。

语法:

background-size: auto | <长度值> | <百分比> | cover | contain

取值说明:

1、auto:默认值,不改变背景图片的原始高度和宽度;

2、<长度值>:成对出现如200px 50px,将背景图片宽高依次设置为前面两个值,当设置一个值时,将其作为图片宽度值来等比缩放

3、<百分比>:0%~100%之间的任何值,将背景图片宽高依次设置为所在元素宽高乘以前面百分比得出的数值,当设置一个值时同上;

4、cover:顾名思义为覆盖,即将背景图片等比缩放以填满整个容器

5、contain:容纳,即将背景图片等比缩放至某一边紧贴容器边缘为止

提示:大家可以在右边的编辑窗口输入自己的代码尝试不同取值的效果。

multiple backgrounds

多重背景,也就是CSS2里background的属性外加originclipsize组成的新background的多次叠加,缩写时为用逗号隔开的每组值;用分解写法时,如果有多个背景图片,而其他属性只有一个(例如background-repeat只有一个),表明所有背景图片应用该属性值。

语法缩写如下:

background : [background-color] | [background-image] | [background-position][/background-size] | [background-repeat] | [background-attachment] | [background-clip] | [background-origin],...

可以把上面的缩写拆解成以下形式:

background-image:url1,url2,...,urlN;

background-repeat : repeat1,repeat2,...,repeatN;
backround-position : position1,position2,...,positionN;
background-size : size1,size2,...,sizeN;
background-attachment : attachment1,attachment2,...,attachmentN;
background-clip : clip1,clip2,...,clipN;
background-origin : origin1,origin2,...,originN;
background-color : color;

注意:

  1. 用逗号隔开每组 background 的缩写值;
  2. 如果有 size 值,需要紧跟 position 并且用 "/" 隔开;
  3. 如果有多个背景图片,而其他属性只有一个(例如 background-repeat 只有一个),表明所有背景图片应用该属性值。
  4. background-color 只能设置一个。

举例:

有三张单独的图片:

使用多背景技术实现:

例子:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>多重背景</title>
<style type="text/css">
.demo{
width: 300px;
height: 140px;
border: 1px solid #999; background-image: url(http://img.mukewang.com/54cf2365000140e600740095.jpg),
url(http://img.mukewang.com/54cf238a0001728d00740095.jpg),
url(http://img.mukewang.com/54cf23b60001fd9700740096.jpg);
background-position: left top, 100px 0, 200px 0;
background-repeat: no-repeat, no-repeat, no-repeat; margin:0 0 20px 0;
}
.task {
width: 300px;
height: 140px;
border: 1px solid #999; background:url(http://static.mukewang.com/static/img/logo_index.png) left top/75% 50% no-repeat,
url(http://static.mukewang.com/static/img/logo_index.png) right bottom/50% 45% no-repeat; } </style>
</head>
<body>
<div class="demo"></div>
<div class="task"></div>
</body>
</html>

效果:

【CSS3】---background-origin background-clip background-size的更多相关文章

  1. 【CSS3】Advanced8:CSS Backgrounds: Multiples, Size, and Origin

    1.Multiples,Size,and Origin eg:background-image:url(bg.png),url(bullet.png) 0 50% no-repeat,url(arro ...

  2. 【CSS3】 - 初识CSS3

    .navdemo{ width:560px; height: 50px; font:bold 0/50px Arial; text-align:center; margin:40px auto 0; ...

  3. 【微信支付】分享一个失败的案例 跨域405(Method Not Allowed)问题 关于IM的一些思考与实践 基于WebSocketSharp 的IM 简单实现 【css3】旋转倒计时 【Html5】-- 塔台管制 H5情景意识 --飞机 谈谈转行

    [微信支付]分享一个失败的案例 2018-06-04 08:24 by stoneniqiu, 2744 阅读, 29 评论, 收藏, 编辑 这个项目是去年做的,开始客户还在推广,几个月后发现服务器已 ...

  4. 【android】ImageView的src和background的区别以及两者的妙用

    一.ImageView中XML属性src和background的区别: background会根据ImageView组件给定的长宽进行拉伸,而src就存放的是原图的大小,不会进行拉伸 .src是图片内 ...

  5. 【android】ImageView的src和background以及两者之间的神奇的差异

    一.ImageView中XML属性src和background的差别: background会依据ImageView组件给定的长宽进行拉伸.而src就存放的是原图的大小,不会进行拉伸.src是图片内容 ...

  6. -_-#【CSS3】CSS3 gradient transition with background-position

    CSS3 gradient transition with background-position <!DOCTYPE html> <html> <head> &l ...

  7. 【CSS3】---first-of-type选择器+nth-of-type(n)选择器

    first-of-type选择器 “:first-of-type”选择器类似于“:first-child”选择器,不同之处就是指定了元素的类型,其主要用来定位一个父元素下的某个类型的第一个子元素. 示 ...

  8. 【CSS3】选择器

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. 【css3】画‘百分比圆’

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

随机推荐

  1. EXTJS AJAX解析XML数据

    public String getAllAreaInfos() { try { List<Areainfo> list = null; if(areaName!=null&& ...

  2. Java内存区域分析

    程序计数器 指令运行的指示器. 每一个线程都有独立的程序计数器,互无影响,我们称这类区域为线程私有的内存. 运行Java方法,计数器记录的是正在运行的虚拟机字节码指令地址;假设运行的是native方法 ...

  3. 【转】浅析linux内存模型

    转自:http://pengpeng.iteye.com/blog/875521 0. 内存基本知识 我们通常称 linux的内存子系统为:虚拟内存子系统(virtual memory system) ...

  4. Codeforces Beta Round #6 (Div. 2 Only) E. Exposition multiset

    E. Exposition Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/ ...

  5. Java虚拟机的启动与程序的执行

    这篇文章是从 OpenJDK 源码的角度讲当我们执行了 java -classpath . hello 之后,java.exe 怎样从 main 函数開始运行,启动虚拟机,并运行字节码中的代码. 实验 ...

  6. Some tips on using HashSet<T> and List<T>

    This article is written based on my colleague's review Most of the times, when I want to use a colle ...

  7. 0c-38-ARC快速入门

    2.ARC快速使用 int main(){ Student *s = [[Student alloc] init]; return 0; } 只需要写一行代码,编译器会在合适的位置释放学生对象,程序员 ...

  8. 调用百度地图Api实现的查看地图功能的小插件

    1. 功能 bMap.js 可根据地理位置调用出百度地图,采用弹出框形式 2.用法 var city = '青岛市'; var address = '香港中路'; bMap.init({ city : ...

  9. java实现迷宫算法--转

    沿着所有方向进行探测,有路径则走,没有路径则从栈中回退. 回溯法是一种不断试探且及时纠正错误的搜索方法,下面的求解过程采用回溯法.从入口出发,按某一方向向前探索,若能走通(未走过的),即某处可以到达, ...

  10. 龙书(Dragon book) +鲸书(Whale book)+虎书(Tiger book)

    1.龙书(Dragon book)书名是Compilers: Principles,Techniques,and Tools作者是:Alfred V.Aho,Ravi Sethi,Jeffrey D. ...