当前位置:K88软件开发文章中心编程语言Css/Css3Css/Css301 → 文章内容

CSS3 背景

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-10 12:06:59

CSS3 背景CSS3 背景CSS3中包含几个新的背景属性,提供更大背景元素控制。在本章您将了解以下背景属性:background-imagebackground-sizebackground-originbackground-clip您还将学习如何使用多重背景图像。浏览器支持表格中的数字表示支持该属性的第一个浏览器版本号。紧跟在 -webkit-, -ms- 或 -moz- 前的数字为支持该前缀属性的第一个浏览器版本号。属性background-image(with multiple backgrounds)4.09.03.63.111.5background-size4.01.0 -webkit-9.04.03.6 -moz-4.13.0 -webkit-10.510.0 -o-background-origin1.09.04.03.010.5background-clip4.09.04.03.010.5CSS3 background-image属性CSS3中可以通过background-image属性添加背景图片。不同的背景图像和图像用逗号隔开,所有的图片中显示在最顶端的为第一张。实例





#example1 {background-image:





url(img_flwr.gif), url(paper.gif);background-position:





right bottom, left top;background-repeat:





no-repeat, repeat;}尝试一下 ?可以给不同的图片设置多个不同的属性实例





#example1 {background:





url(img_flwr.gif) right bottom no-repeat, url(paper.gif) left top repeat;}尝试一下 ?CSS3 background-size 属性background-size指定背景图像的大小。CSS3以前,背景图像大小由图像的实际大小决定。 CSS3中可以指定背景图片,让我们重新在不同的环境中指定背景图片的大小。您可以指定像素或百分比大小。你指定的大小是相对于父元素的宽度和高度的百分比的大小。实例 1重置背景图像:div{background:





url(img_flwr.gif);background-size:





80px 60px;background-repeat:





no-repeat;}尝试一下 ?实例 2伸展背景图像完全填充内容区域:div{background:





url(img_flwr.gif);background-size:





100% 100%;background-repeat:





no-repeat;}尝试一下 ?CSS3的background-Origin属性background-Origin属性指定了背景图像的位置区域。content-box, padding-box,和 border-box区域内可以放置背景图像。 实例在 content-box 中定位背景图片:div{background:





url(img_flwr.gif);background-repeat:





no-repeat;background-size:





100% 100%;background-origin:





content-box;}尝试一下 ?CSS3 多个背景图像CSS3 允许你在元素上添加多个背景图像。实例在 body 元素中设置两个背景图像:body{background-image:





url(img_flwr.gif),url(img_tree.gif);}尝试一下 ?CSS3 background-clip属性CSS3中background-clip背景剪裁属性是从指定位置开始绘制。实例





#example1 {border:





10px dotted black;padding:





35px;background:





yellow;background-clip:





content-box;}尝试一下 ?新的背景属性顺序描述CSSbackground-clip规定背景的绘制区域。3background-origin规定背景图片的定位区域。3background-size规定背景图片的尺寸。3

CSS3 背景