一、背景属性

  1.1、背景颜色background-color

    <style>
/*浮动,横向排列*/
div{float: left;} /*background-color属性值支持三种形式:
name - 指定颜色的名称,如 "red" ;
RGB - 指定 RGB 值, 如 "rgb(255,0,0)" ;
Hex - 指定16进制值, 如 "#ff0000"。*/ .one{
width: 100px;
height: 100px;
background-color: red;
}
.two{
width: 100px;
height: 100px;
background-color: rgb(0,277,0);
}
.three{
width: 100px;
height: 100px;
background-color:#66FFFF;
}
</style> <body>
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
</body>

    代码执行如下图:

  1.2、背景图片background-iamge

    <style>
div{
width: 200px;
height: 200px;
border: 3px solid red;
background-image: url(img/love.jpg);
}
</style> <body>
<div></div>
</body>

    代码执行如下图:

  1.3、背景是否重复background-repeat

    <style>
div{
width: 490px;
height: 200px;
border: 3px solid red;
background-image: url(img/love.jpg);
/*默认 重复repeat*/
background-repeat:no-repeat;
}
</style>

    代码执行如下图:

  

  1.4、背景是否固定background-attachmen(属性值默认为scroll)

    <style>
body{
width: 490px;
height: 200px;
background-image: url(img/love.jpg);
background-repeat:no-repeat;
background-attachment:fixed;
}
</style>

    默认scroll效果图:

    设置fixed运行效果图:

  1.5、背景图像的开始位置background-position

    

  

    <style>
div{
float: left;
width: 300px;
height: 300px;
border: 3px solid red;
margin: 10px;
background-image: url(img/love.jpg);
background-repeat:no-repeat;
}
.one{
background-position: center;
}
.two{
background-position: bottom right;
}
.three{
background-position: 10% 40%;
}
.four{
background-position: 40px 10px;
}
</style> <body>
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
<div class="four"></div>
</body>

    代码执行效果图:

二、背景复合样式background(颜色可以写在最前面|最后面)

    <style>
/*复合样式下设置fixed后position位置根据可视区域设置
 复合样式下设置scroll后position位置根据元素自身设置*/
div.one{
width: 700px;
height: 300px;
border: 3px solid #000;
background:pink url(img/love.jpg) no-repeat scroll center;
}
</style>

第三、兼容

所有浏览器都支持 background 属性。

注意:inherit:IE7 以及更早的浏览器不支持 "inherit"。IE8 需要声明 !DOCTYPE。IE9 支持 "inherit"。

最新文章

  1. 我的AngularJS 学习之旅(二)
  2. ThinkPHP5.0完全开发手册
  3. hadoop中master免登录slave
  4. 【itclx面向对象一】tcl基础语法:过程、作用域、以及itcl面向编程回顾
  5. Jmeter使用——参数化
  6. qt5集成libcurl实现tftp和ftp的方法一:搭建环境(五篇文章)
  7. Pymsql
  8. Synchronize,Lock, ReentrantLock,ReentrantReadWriteLock
  9. 兄弟连学python---Socket介绍
  10. 【EFM32】EFM32芯片解锁、加锁操作
  11. promise.then, setTimeout,await执行顺序问题
  12. mysql列反转Pivoting
  13. 爬虫----BeautifulSoup模块
  14. ajax 调用 java webapi 多个参数(二)
  15. java操作Hbase
  16. 为什么要使用日志管理?syslog和Windows事件日志
  17. Todolist分别用React与Vue的实现与思考
  18. 转:winform 打包自动安装数据库
  19. 【BZOJ1489】[HNOI2009]双递增序列(动态规划)
  20. Postman 发送 Bearer token

热门文章

  1. nmon安装与使用
  2. 高校表白APP-冲刺第四天
  3. webservice接口的开发和调用
  4. 后端必备的Linux知识
  5. PL/SQL变量和类型
  6. concurrent.futures进行并发编程
  7. ajax的一些相关
  8. SP913 QTREE2 - Query on a tree II
  9. Mybatis注解和配置文件命名规范所引发的问题
  10. struts.xml,报错 1 c.opensymphony.xwork2.util.DomHelper