CSS 中关于background 属性功能
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 属性功能的更多相关文章
- css中设置background属性
属性解释 background属性是css中应用比较多,且比较重要的一个属性,它是负责给盒子设置背景图片和背景颜色的,background是一个复合属性,它可以分解成如下几个设置项: backgrou ...
- css中的background属性
第一次写博客,我就写写今天在编写网页的过程中,对background的两种运用,一是background中的线性渐变,对背景的渐变我其实是很少使用的,所以今天在写的时候我用css3的帮助手册,back ...
- Css中的Position属性
Css中的Position属性 Css属性在线查询地址: http://www.css88.com/book/css/properties/index.htm CSS 中的 position 属性 在 ...
- 深入理解css中的margin属性
深入理解css中的margin属性 之前我一直认为margin属性是一个非常简单的属性,但是最近做项目时遇到了一些问题,才发现margin属性还是有一些“坑”的,下面我会介绍margin的基本知识以及 ...
- 理解与应用css中的display属性
理解与应用css中的display属性 display属性是我们在前端开发中常常使用的一个属性,其中,最常见的有: none block inline inline-block inherit 下面, ...
- CSS中的display属性(none,block,inline,inline-block,inherit)
css中的display属性(none,block,inline,inline-block,inherit) display属性是我们在前端开发中常常使用的一个属性,其中,最常见的有: none bl ...
- css中的定位属性position(转)
css中的定位属性position 同样的也是上课的时候发现学生难以理解的一些问题拿出来记录一下,希望帮助初学者. 在css中定位属性position的运用在页面中是很常用的,特别是一些结合js来 ...
- CSS中的display属性
CSS中的display属性 display:block是可以把非块级元素强制转换为块级元素显示,如内嵌元素span,原来不支持设置宽高,宽度是由内容撑开的,几个span元素是在同一行内的,如果给sp ...
- 举例详解CSS中的cursor属性
这篇文章主要举例介绍了CSS中的cursor属性,包括zoom-in/zoom-out和grab/grabbing等常用属性值的使用,需要的朋友可以参考下 一.开篇之言 CSS3的领域范围已经渗透到了 ...
随机推荐
- 时隔一年再读到the star
The Star Arthur C. Clarke It is three thousand light-years to the Vatican. Once, I believed that spa ...
- java 上传图片
1.导入smartupload.jar包 ,添加uploadIMG.jsp,upfileIMG.jsp. 2.需要在项目下面建立一个保存文件的文件夹pic或者upload 3.在调用的地方调用子框架u ...
- redis 命令
添加数据 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo } span.s1 { } set key value //添加多条数据 ...
- neo4j-访问提示No authorization header supplied.
在使用java连接neo4j数据库时 public static void main(String[] args) throws SQLException { Connection con = Dri ...
- sql分页操作
看到了网上关于分页的讲解 对最快的分页语句做了测试 还别说速度真快 总共6w条数据 速度确实so 快 前提是id是主键 或者是索引 declare @page int;--页数 declare @P ...
- [日常训练]string
Description 给定一个长度为$n$的字符串,串中的字符保证是前$k$个小写字母.你可以在字符串后再添加$m$个字符,使得新字符串所包含的不同的子序列数量尽量多.当然,前提是只能添加前$k$个 ...
- 【codeforces 749E】 Inversions After Shuffle
http://codeforces.com/problemset/problem/749/E (题目链接) 题意 给出一个1~n的排列,从中等概率的选取一个连续段,设其长度为l.对连续段重新进行等概率 ...
- javascript操作字符串的方法
string.indexOf()//返回字符串中第一个与给定子串匹配的子串序号字符串的IndexOf()方法搜索在该字符串上是否出现了作为参数传递的字符串,如果找到字符串,则返回字符的起始位置 (0表 ...
- java重置定时器频率
public class BallUtil { public static Timer fisTimer ; public static void fisStartBall(){ long first ...
- AnjularJS系列2 —— 表单控件功能相关指令
第二篇,表单控件功能相关指令. ng-checked控制radio和checkbox的选中状态 ng-selected控制下拉框的选中状态 ng-disabled控制失效状态 ng-multiple控 ...