收藏 分享(赏)

css边框与背景[下].docx

上传人:天天快乐 文档编号:430724 上传时间:2018-04-05 格式:DOCX 页数:6 大小:39.88KB
下载 相关 举报
css边框与背景[下].docx_第1页
第1页 / 共6页
css边框与背景[下].docx_第2页
第2页 / 共6页
css边框与背景[下].docx_第3页
第3页 / 共6页
css边框与背景[下].docx_第4页
第4页 / 共6页
css边框与背景[下].docx_第5页
第5页 / 共6页
点击查看更多>>
资源描述

1、第 17 章 CSS 边框与背景 下学习要点:1.设置背景本章主要探讨 HTML5 中 CSS 边框和背景,通过边框和背景的样式设置,给元素增加 更丰富的外观。一设置背景盒 模 型 的 尺 寸 可 以 通 过 两 种 方 式 实 现 可 见 性 , 一 种 就 是 之 前 的 边 框 , 还 有 一 种 就 是 背 景 。CSS 背景设置的样式表如下:属性 值 说明 CSS 版本background-color 颜色 背景的颜色 1background-image none 或 url 背景的图片 1/3background-repeat 样式名称 背景图片的样式 1/3background-

2、size 长度值或其他 背景图像的尺寸 3background-position 位置坐标 背景图像的位置 1background-attachment 滚动方式 背景图片的滚动 1/3background-clip 裁剪方式 背景图片的裁剪 3background-origin 位置坐标 背景图片起始点 3background 复合值 背景图片简写方式 11.background-color 颜色值 说明 CSS 版本颜色 设置背景颜色为指定色 1transparent 设置背景颜色为透明色 1div background-color: silver;解释:设置元素的背景颜色。属性值是颜色值

3、。div b background-color: transparent;解释:默认值为 transparent,为透明的意思。这样 内部的元素就会继承 的 背 景 色 。 一 般 来 说 这 个 属 性 使 用 频 率 很 低 , 原 因 是 不 需 要 改 变 色 彩 时 就 默 认 , 需 要 改 变 色 彩时又是颜色值。body background-color: silver;解释:在元素下可以设置整个页面的背景色。2.background-image值 说明 CSS 版本none 取消背景图片的设置 1url 通过 URL 设置背景图片 1body background-image

4、: url(loading.gif);解 释 : url 里 面 是 图 片 的 路 径 , 设 置 整 个 页 面 以 这 个 图 片 为 背 景 , 如 果 图 片 不 足 以 覆 盖 , 则复制扩展。div background-image: none;解释:如果多个 div 批量设置了背景,而其中某一个不需要背景,可以单独设置 none值取消背景。在 CSS3 中,背景图片还设置了比如线性、放射性等渐变方式。但由于支持度的问题, 比如 IE9 尚未支持。我们把这些的新特性放到独立的课程中讲解。3.background-repeat 重复 值 说明 CSS 版本repeat-x 水平方向

5、平铺图像 1repeat-y 垂直方向平铺图像 1Repeat(默认) 水平和垂直方向同时平铺图像 1no-repeat 禁止平铺图像 1body background-image: url(loading.gif); background-repeat: no-repeat;解释:让背景图片只显示一个,不平铺。CSS3 还提供了两个值,由于支持度不佳,这 里忽略。4.background-position 背景定位值 说明 CSS 版本top 顶 将背景图片定位到元素顶部 1left 左 将背景图片定位到元素左部 1right 右 将背景图片定位到元素右部 1bottom 底 将背景图片定位

6、到元素底部 1center 居中 将背景图片定位到元素中部 1长度值 使用长度值偏移图片的位置 1百分数 使用百分数偏移图片的位置 1body background-image: url(loading.gif); background-repeat: no-repeat; background-position: top;解释:将背景图片置于页面上方,如果想置于左上方则值为:top left。body background-image: url(loading.gif); background-repeat: no-repeat; background-position: 20px 20px

7、;解释:使用长度值或百分数,第一值表示左边,第二个值表示上边。5.background-size值 说明 CSS 版本auto 默认值,图像以本尺寸显示 3cover 等比例缩放图像,使图像至少覆盖容器,但有可能超出容器 3contain 等比例缩放图像,使其宽度、高度中较大者与容器横向或纵向重合 3长度值 CSS 长度值,比如 px、em 3百分数 比如:100% 3body background-image: url(loading.gif); background-size: cover;解释:使用 cover 相当于 100%,全屏铺面一张大图,这个值非常实用。在等比例放大 缩小的过程

8、中,可能会有背景超出,当然,这点无伤大雅。div background-image: url(loading.gif); background-size: contain;解释:使用 contain 表示,尽可能让图片完整的显示在元素内。body background-image: url(loading.gif); background-size: 240px 240px;解释:长度值的用法,分别表示长和高。6.background-attachment 背景是否是随内容动。值 说明 CSS 版本scroll 默 认 值 , 背 景 固 定 在 元 素 上 , 不 会 随 着 内容一起滚动

9、1fixed 背景固定在视窗上,内容滚动时背景不动 1body background-image: url(loading.gif); background-attachment: fixed;解释:fixed 属性会导致背景产生水印效果,拖动滚动条而背景不动。7.background-origin 背景起始位置border-box,这个参数取值,必须设置 border;后面两个参数,必须设置 padding 才有效果。 值 说明 CSS 版本border-box 在元素盒子内部绘制背景 3padding-box 在内边距盒子内部绘制背景 3content-box 在内容盒子内部绘制背景 3d

10、iv width: 400px; height: 300px;border: 10px dashed red; padding: 50px;background-image: url(img.png); background-repeat: no-repeat; background-origin: content-box;解释:设置背景起始位置。8.background-clip值 说明 CSS 版本border-box 在元素盒子内部裁剪背景 3padding-box 在内边距盒子内部裁剪背景 3content-box 在内容黑子内部裁剪背景 3div width: 400px; heig

11、ht: 300px;border: 10px dashed red; padding: 50px;background-image: url(img.png); background-repeat: no-repeat; background-origin: border-box; background-clip: padding-box;解释:在内边距盒子内部裁剪背景。9.backgrounddiv width: 400px; height: 300px;border: 10px dashed red; padding: 50px;background: silver url(img.png) no-repeat scroll left top/100% border-box content-box;解释:完整的简写顺序如下:颜色 图片 重复 是否移动 定位 大小 起始位置 裁剪。background-color background-imagebackground-repeat background-attachmentbackground-position / background-size background-originbackground-clip;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 经营企划

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报