background 是 css中的核心属性,我们对他应该充分了解。

background-image   定义背景图像  这个属性是我们用的最多的属性

设置背景图像有两个方式

background: url("img/01.jpg") ; 或者 background-image: url("img/01.jpg");

background-color     定义背景颜色 (三个属性)

属性为元素设置一种纯色。这种颜色会填充元素的内容、内边距和边框区域,扩展到元素边框的外边界(但不包括外边距)。如果边框有透明部分(如虚线边框),会透过这些透明部分显示出背景色。

1.currentColor顾名思意就是“当前颜色”,准确讲应该是“当前的文字颜色”,这是css3中新加的关键字 比如 :border: 1px solid currentColor 是指当前标签所继承文字的颜色

http://www.zhangxinxu.com/wordpress/2014/10/currentcolor-css3-powerful-css-keyword/   这个是currentColor 的具体描述 。

2.  transparent   尽管在大多数情况下,没有必要使用 transparent。不过如果您不希望某元素拥有背景色,同时又不希望用户对浏览器的颜色设置影响到您的设计,那么设置 transparent 值还是有必要的。

3. inherit是继承,继承块中的颜色 (这个具体的用法我也不清楚,基本上没有用过。)

background-origin    指定背景的显示区域

该属性指定了背景从哪个区域(边框、补白或内容)开始绘制,但也仅仅能控制背景开始绘制的位置,你可以用这个属性在边框上绘制背景,

1. padding-box    背景图像相对于内边距框来定位。

.box {
width: 300px;
height: 400px;
background: url("im/1.jpg") no-repeat;         
background-origin: border-box;
padding: 50px;
border: 50px solid orange;
margin: auto;
margin-top: 100px;
}

2. border-box    背景图相对于边框盒来定位。

.box {
width: 300px;
height: 400px;
background: url("im/1.jpg") no-repeat;
background-origin: border-box;
padding: 50px;
border: 50px solid orange;
margin: auto;
margin-top: 100px;

}

3. content-box   背景图像相对于内容框来定位。

.box {
width: 300px;
height: 400px;
background: url("im/1.jpg") no-repeat;
background-origin: content-box;
padding: 50px;
border: 50px solid orange;
margin: auto;
margin-top: 100px;
}

background-clip       指定背景的裁剪区域

该属性指定了背景在哪些区域可以显示,但与背景开始绘制的位置无关,背景的绘制的位置可以出现在不显示背景的区域,这时就相当于背景图片被不显示背景的区域裁剪了一部分一样。

如果它的值为border,则背景在元素的边框、补白和内容区域都会显示;如果值为padding,则背景只会在补白和内容区域显示;如果值为content,则背景只会在内容区域显示。

1.padding-box   从padding区域向外剪裁背景

.box {
width: 300px;
height: 300px;
background: url("im/1.jpg") no-repeat;
background-clip: padding-box;
background-origin: padding-box;
padding: 50px;
border: 50px dashed orange;
margin: auto;
margin-top: 100px;
}

2.border-box   从border区域向外剪裁背景

.box {
width: 300px;
height: 300px;
background: url("im/1.jpg") no-repeat;
background-clip: border-box;;
background-origin: padding-box;
padding: 50px;
border: 50px dashed orange;
margin: auto;
margin-top: 100px;
}

3.content-box   从content区域向外剪裁背景

.box {
width: 300px;
height: 300px;
background: url("im/1.jpg") no-repeat;
background-clip: content-box;
background-origin: padding-box;
padding: 50px;
border: 50px dashed orange;
margin: auto;
margin-top: 100px;
}

background-repeat   设置背景图片是否及其如何重复铺排

1.   repeat: 平铺整个页面,左右与上下

.box {
width: 600px;
height: 600px;
background: url("im/1.jpg");
background-repeat:repeat;
border: 10px dashed orange;
margin: auto;
margin-top: 100px;
}

2.   repeat-x: 在x轴上平铺,左右

.box {
width: 600px;
height: 600px;
background: url("im/1.jpg");
background-repeat:repeat-x;
border: 10px dashed orange;
margin: auto;
margin-top: 100px;
}

3.   repeat-y: 在y轴上平铺,上下

.box {
width: 600px;
height: 600px;
background: url("im/1.jpg");
background-repeat:repeat-y;
border: 10px dashed orange;
margin: auto;
margin-top: 100px;
}

4.   no-repeat: 图片不重复

.box {
width: 600px;
height: 600px;
background: url("im/1.jpg");
background-repeat:no-repeat;
border: 10px dashed orange;
margin: auto;
margin-top: 100px;
}

background-size       定义背景图片的大小

1.  初始值 auto

.box {
width: 600px;
height: 600px;
background: url("im/1.jpg")no-repeat;
background-size: auto;
border: 10px dashed orange;
margin: auto;
margin-top: 100px;
}

2.  cover  保持背景图像本身的宽高比例,将图片缩放到正好完全覆盖所定义背景区域。

.box {
width: 600px;
height: 600px;
background: url("im/1.jpg")no-repeat;
background-size: cover;
border: 10px dashed orange;
margin: auto;
margin-top: 100px;
}

3.  contain  保持图像 本身的宽高比例,将图片缩放到宽度或高度正好适应所定义背景的区域。

.box {
width: 600px;
height: 600px;
background: url("im/1.jpg")no-repeat;
background-size:contain;
border: 10px dashed orange;
margin: auto;
margin-top: 100px;
}

background-position  设置背景图片的位置

1.  最主要使用在 一张png 上有多个logo 或者 ico  这个时候就用到background-position了

2.  background-position: 15px 20px;(指将图片向右移15px,向下移20px;)  就是以图片的左上角顶点为原点,往下和右都为正,反之为负,

3. background-position : centen  centen   靠右居中。

background-attachment  定义背景图像的显示方式

1.   scroll: 随着页面的滚动轴背景图片将移动

背景图是相对于元素自身固定,内容动时背景图也动,附加到元素的border

2.   fixed: 随着页面的滚动轴背景图片不会移动

背景图片相对于视口固定,就算元素有了滚动条,背景图也不随内容移动。

3.  local  :   则背景会随内容的滚动而滚动。

因为背景图是相对于元素自身内容定位,开始固定,元素出现滚动条后背景图随内容而滚动。

div{
width: 200px;
height: 350px;
border: 1px solid red;
background-image: url("im/1.jpg");
background-repeat: no-repeat;
background-attachment: local;
overflow: scroll;
line-height: 1.5;
}

</style>
</head>
<body>
<div>
1内容超出会出现滚动条
2内容超出会出现滚动条
3内容超出会出现滚动条
4内容超出会出现滚动条
5内容超出会出现滚动条
6内容超出会出现滚动条
7内容超出会出现滚动条
8内容超出会出现滚动条
9内容超出会出现滚动条
10内容超出会出现滚动条
11内容超出会出现滚动条
12内容超出会出现滚动条
13内容超出会出现滚动条
14内容超出会出现滚动条
15内容超出会出现滚动条
16内容超出会出现滚动条
17内容超出会出现滚动条
18内容超出会出现滚动条
19内容超出会出现滚动条
20内容超出会出现滚动条
</div>
</body>

CSS 中关于background 属性功能的更多相关文章

  1. css中设置background属性

    属性解释 background属性是css中应用比较多,且比较重要的一个属性,它是负责给盒子设置背景图片和背景颜色的,background是一个复合属性,它可以分解成如下几个设置项: backgrou ...

  2. css中的background属性

    第一次写博客,我就写写今天在编写网页的过程中,对background的两种运用,一是background中的线性渐变,对背景的渐变我其实是很少使用的,所以今天在写的时候我用css3的帮助手册,back ...

  3. Css中的Position属性

    Css中的Position属性 Css属性在线查询地址: http://www.css88.com/book/css/properties/index.htm CSS 中的 position 属性 在 ...

  4. 深入理解css中的margin属性

    深入理解css中的margin属性 之前我一直认为margin属性是一个非常简单的属性,但是最近做项目时遇到了一些问题,才发现margin属性还是有一些“坑”的,下面我会介绍margin的基本知识以及 ...

  5. 理解与应用css中的display属性

    理解与应用css中的display属性 display属性是我们在前端开发中常常使用的一个属性,其中,最常见的有: none block inline inline-block inherit 下面, ...

  6. CSS中的display属性(none,block,inline,inline-block,inherit)

    css中的display属性(none,block,inline,inline-block,inherit) display属性是我们在前端开发中常常使用的一个属性,其中,最常见的有: none bl ...

  7. css中的定位属性position(转)

    css中的定位属性position   同样的也是上课的时候发现学生难以理解的一些问题拿出来记录一下,希望帮助初学者. 在css中定位属性position的运用在页面中是很常用的,特别是一些结合js来 ...

  8. CSS中的display属性

    CSS中的display属性 display:block是可以把非块级元素强制转换为块级元素显示,如内嵌元素span,原来不支持设置宽高,宽度是由内容撑开的,几个span元素是在同一行内的,如果给sp ...

  9. 举例详解CSS中的cursor属性

    这篇文章主要举例介绍了CSS中的cursor属性,包括zoom-in/zoom-out和grab/grabbing等常用属性值的使用,需要的朋友可以参考下 一.开篇之言 CSS3的领域范围已经渗透到了 ...

随机推荐

  1. CodeAtlas For Sublime Text

    CodeAtlas is a plugin of SublimeText, which allows one to explore the call graph conveniently. The p ...

  2. [LeetCode] Power of Four 判断4的次方数

    Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example: Gi ...

  3. [LeetCode] Strobogrammatic Number II 对称数之二

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

  4. [LeetCode] Binary Tree Level Order Traversal II 二叉树层序遍历之二

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  5. Ajax入门(一)

    最近开始学习Ajax了0.0,虽然其他的还没巩固,但既然学了就先写下来吧... Ajax的定义呢,百度吧= =...就觉得最实用的地方就是页面无刷新,但网页实现了与后台的同步更新.   1, 首先创建 ...

  6. svn自动update到指定目录

    对于开发和测试环境来说,可以使用svn自动update 到指定目录,这样就省去每次提交代码都要去服务器上手动update.对于团队来说,省时省力. 看下怎么做吧,在服务器svnserver安装 目录下 ...

  7. jquery版滑块导航栏

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <script src ...

  8. Leetcode分类刷题答案&心得

    Array 448.找出数组中所有消失的数 要求:整型数组取值为 1 ≤ a[i] ≤ n,n是数组大小,一些元素重复出现,找出[1,n]中没出现的数,实现时时间复杂度为O(n),并不占额外空间 思路 ...

  9. ActiveMQ入门实例Demo

    前面我们已经搭建和配置好了ActiveMQ,下面来看一个Demo,体验一下MQ. JMS 消息模型 JMS消息服务应用程序结构支持两种模型:点对点模型,发布者/订阅者模型. (1)点对点模型(Queu ...

  10. mysql-You can’t specify target table for update in FROM clause错误

    mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表( ...