一、背景属性

  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"。

background——背景属性的更多相关文章

  1. css中background背景属性概

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

  2. CSS探案之 background背景属性剖析

    首先,我们先来看看两个css属性:background和background-color,对!就是这两位,相信大家在平时应该没少 麻烦人家把,反正我是这样,几乎也少会用到背景图,原因很简单:就是有点害 ...

  3. css中background背景属性概述

    background:url(背景图片路径) no-repeat;/*不重复默认在左上方*/ background:url(背景图片路径) no-repeat center;/*不重复背景图片中间显示 ...

  4. css background 背景知识详解

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

  5. background的属性和背景图片定位的实例

    本文内容: 1.背景图片定位示例 2.background常用的属性值 3.background-repeat新增的round.space属性 4.background-size的属性值(着重介绍co ...

  6. CSS背景属性Background详解

    [转] 本文详解了CSS的背景属性Background,包括CSS3中新增的背景属性.如果你是个CSS初学者,还可以查看之前介绍的CSS浮动属性和CSS透明属性详解. CSS2 中有5个主要的背景(b ...

  7. CSS下背景属性background的使用方法

    背景颜色(background-color) CSS可以用纯色来作为背景,也可以将背景设置为透明,background相当于xhtml中的bgcolor. 它的两个值: transparent(默认值 ...

  8. CSS背景属性background

    background属性是所有背景属性的缩写: 以下是这些背景属性: background-color:背景颜色 你可以通过颜色名称(red/green/blue)来设置 也可以用十六进制(#fff/ ...

  9. background 背景类八大属性

    background 背景类八大属性 背景颜色(当同时定义了背景颜色和背景图像时,背景图像覆盖在背景颜色之上) background-image:背景图像 background-repeat:背景图像 ...

随机推荐

  1. html5css练习 旋转

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

  2. 福州大学软件工程1916 | W班 作业成绩排名汇总

    评分链接: 第一次作业-准备篇 https://www.cnblogs.com/deerCode/p/10527237.html 第二次作业-结对第一次-文献摘要热词统计原型设计 https://ww ...

  3. 2017.11.19 C语言基础及流水灯实现

    /* 从右往左*/ #include <reg52.h> sbit ADDR0 = P1^0; sbit ADDR1 = P1^1; sbit ADDR2 = P1^2; sbit ADD ...

  4. CentOS7──xxx is not in the sudoers file

    提示"xxx is not in the sudoers file. This incident will be reported.其中 ”XXX“是你的用户名,也就是你的用户名没有权限使用 ...

  5. html5与css3面试题(2)

    10.xhtml与HTML的区别? Html是对web网页设计的语言,而xhtml是基于xml的置标语言 11.面向对象的引用方法分为几种? 内部写的 原型链引用的 12.什么是重载? 函数名相同,但 ...

  6. Jmeter二次开发

    Jmater函数扩展的步骤1. 导入Jmeter源码,或使用maven项目,引入依赖的jar包 2. 继承AbstractFunction,实现自定义Function 3. 继承JMeterTestC ...

  7. Java EE开发技术课程

    新的学期开始了,j2e已经上了两节课,接下来就是对该课程的一些作业以及相关的认识: 一.课程目标: Java EE是java的企业级应用,所以在我看来在学习这门课程之前肯定要对java有一个具体的认识 ...

  8. linux随

    Linux 1991芬兰大学生linus 安全 开源 免费 可靠 (堡垒机)(跳转机) 多用户 多任务 处理并发及速度比windows好很多 命令:ifconfig pwd ls -a -l -t(时 ...

  9. flutter -icons

    icon 合集 https://material.io/tools/icons/?icon=account_balance&style=baseline

  10. Spark大型电商项目实战-及其改良(2) RDD优化效果不稳定的真正原因

    首先看没有map join的第2任务: 时间线如下 接着是对应id的算子计算时间表 Stage Id Description Submitted Duration Tasks: Succeeded/T ...