css背景样式

序号  中文说明  标记语法  
1  背景颜色  {background-color:数值}  
2  背景图片  {background-image: url('imgpath/img.png')|none}  
3  背景重复  {background-repeat:inherit|no-repeat|repeat|repeat-x|repeat-y}  
4  背景固定  {background-attachment:fixed|scroll}  
5  背景定位  {background-position:数值|top|bottom|left|right|center}  
6  背影样式  {background:背景颜色|背景图象|背景重复|背景附件|背景位置}

1.背景颜色:background-color

语法: {background-color:数值}
说明: 参数取值和颜色属性一样
注意: 在 HTML当中,要为某个对象加上背景色只有一种办法,那就是先做一个表格,在表格中设置完背景色,再把对象放进单元格。这样做比较麻烦,不但代码较多,还要为表格的大小和定位伤些脑筋。现在用CSS就可以轻松地直接搞定了,而且对象的范围很广,可以是一段文字,也可以只是一个单词或一个字母。 
例子: <span style="background-color:red">给部分文字加背景颜色</span>给部分文字加背景颜色

表格背影颜色:style="background-color:red"

2.背景图片:background-image

语法: {background-image: url(http://www.jb51.net/URL)|none}
说明: URL就是背景图片的存放路径。如果用“none”来代替背景图片的存放路径,将什么也不显示。
例子: 给部分文字加背景图片 .imgbgstyle { background-image: url(http://www.jb51.net/logo.gif)}

3.背景重复:background-repeat

语法: {background-repeat:inherit|no-repeat|repeat|repeat-x|repeat-y}
作用: 背景图片重复控制的是背景图片平铺与否,也就是说,结合背景定位的控制可以在网页上的某处单独显示一幅背景图片
说明: 参数取值范围:
·inherit 继承 
·no-repeat 不重复平铺背景图片
·repeat
·repeat-x 使图片只在水平方向上平铺 
·repeat-y 使图片只在垂直方向上平铺 
注意: 如果不指定背景图片重复属性,浏览器默认的是背景图片向水平、垂直两个方向上平铺。

4.背景固定:background-attachment

语法: {background-attachment:fixed|scroll}
说明: 参数取值范围
·fixed:网页滚动时,背景图片相对于浏览器的窗口而言,固定不动 
·scroll:网页滚动时,背景图片相对于浏览器的窗口而言,一起滚动 
注意: 背景图片固定控制背景图片是否随网页的滚动而滚动。如果不设置背景图片固定属性,浏览器默认背景图片随网页的滚动而滚动。为了避免过于花哨的背景图片在滚动时伤害浏览者的视力,所以可以解除背景图片和文字内容的捆绑,该为和浏览器窗口捆绑。 
例子: 使背景图案不随文字“滚动”的CSS
BODY { background: purple url(http://www.jb51.net/bg.jpg); background-repeat:repeat-y; background-attachment:fixed }

5.背景定位:background-position

语法: {background-position:数值|top|bottom|left|right|center}
作用: 背景定位用于控制背景图片在网页中显示的位置。 
说明: 参数取值范围
·带长度单位的数字参数 
·top:相对前景对象顶对齐 
·bottom:相对前景对象底对齐 
·left:相对前景对象左对齐 
·right:相对前景对象右对齐 
·center:相对前景对象中心对齐 
·比例关系

关键字解释如下:
top left = left top = 0% 0% 
top = top center = center top = 50% 0% 
right top = top right = 100% 0% 
left = left center = center left = 0% 50% 
center = center center = 50% 50% 
right = right center = center right = 100% 50% 
bottom left = left bottom = 0% 100% 
bottom = bottom center = center bottom = 50% 100% 
bottom right = right bottom = 100% 100%

注意: 参数中的center如果用于另外一个参数的前面,表示水平居中;如果用于另外一个参数的后面,表示垂直居中。 

[CSS]background背景的更多相关文章

  1. css background 背景知识详解

    background 背景属性 我们知道元素有前景色color,与之对应的还有背景色,通过background我们可以为元素添加实色(background-color)和任意多个背景图片(backgr ...

  2. css background 背景图设置

  3. CSS 背景-CSS background

    这里有个很好的样式学习网站:http://www.divcss5.com/rumen/r125.shtml 一.Css background背景语法   -   TOP CSS背景基础知识 CSS 背 ...

  4. css中background背景属性概

    css中background背景属性概 background:url(背景图片路径)  no-repeat;/*不重复默认在左上方*/background:url(背景图片路径)  no-repeat ...

  5. css 使用background背景实现border边框效果

    css中,我们一般使用border给html元素设置边框,但也可以使用background背景来模拟css边框效果,本文章向大家介绍css 使用background背景实现border边框效果,需要的 ...

  6. CSS样式表之background背景

    [CSS常用背景属性]:background (缩写形式) background-color:背景色 background-image:背景图  url中放图片地址,背景图和背景色同时存在时,背景图覆 ...

  7. css background之设置图片为背景技巧

    css background之设置图片为背景技巧-css 背景 Background是什么意思,翻译过来有背景意思.同样在css里面作为css属性一成员同样是有背景意思,并且是设置背景图片.背景颜色. ...

  8. CSS background 之设置图片为背景技巧

    首先先来看看background有那些值: 可以按顺序设置如下属性(可点击进入相应的css手册查看使用):background-color 背景颜色background-image 背景图片backg ...

  9. (转)HTML&CSS——background: url() no-repeat 0 -64px;CSS中背景图片定位方法

    http://blog.csdn.net/oscar92420aaa/article/details/51304067 CSS中背景图片的定位,困扰我很久了.今天总算搞懂了,一定要记下来. 在CSS中 ...

随机推荐

  1. PAT 1016. Phone Bills

    A long-distance telephone company charges its customers by the following rules: Making a long-distan ...

  2. (7/18)重学Standford_iOS7开发_视图、绘制、手势识别_课程笔记

    第七课: 1.View 一般来说,视图是一个构造块,代表屏幕上一块矩形区域,定义了一个坐标空间,并在其中绘制及添加触控事件等. ①视图的层级关系 一个视图只能有一个父视图,可以有多个子视图 - ( - ...

  3. sso笔记

    C:\Windows\System32\drivers\etc\hosts SSO:单点登录 1.使用Cookie解决单点登录 技术点: 1.设置Cookie的路径为setPath("/&q ...

  4. 了解node.js

    转载自http://debuggable.com/posts/understanding-node-js:4bd98440-45e4-4a9a-8ef7-0f7ecbdd56cb 当我向人们介绍nod ...

  5. MVC-控制器向View传值的三种方法

    1.提供视图模型对象 你能把一个对象作为View方法的参数传递给视图. public ViewResult Index() { DateTime date = DateTime.Now; return ...

  6. SystemTimeToFileTime、FileTimeToLocalFileTime、LocalFileTimeToFileTime三函数的跨平台实现

    // test.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <stdlib.h>   #include & ...

  7. 使用泛型定义一个可重用的Dao

    dao用来和数据库进行交互,一个项目中,可能有用户表,产品表等等,不可能为每一个表都建立一个dao,使用泛型可以实现通吃. UserDao.java public class UserDao < ...

  8. git的一些基础命令

    Git常用命令 请确保已经安装里git客户端 一般配置 git --version //查看git的版本信息 git config --global user.name //获取当前登录的用户 git ...

  9. xshell连接本地Linux虚拟机!

    终端输入ifconfig获取本地虚拟机的IP地址; 安装openssh-server sudo apt-get install openssh-server 查看server是否启动: ps -ef ...

  10. HTML+CSS基础学习笔记(5)

    一.文字排版--字体 Eg: body{font-family:"宋体";} body{font-family:"Microsoft Yahei";}//微软雅 ...