CSS 背景background的使用方法

时间:2026-02-14 01:54:12

1、首先我们使用实例来说明背景的全部的使用方法和用法,background包括:

background-color

background-image

background-repeat

background-attachment

background-position

CSS 背景background的使用方法

2、首先在网页添加标签,并给标签添加class为back

CSS 背景background的使用方法

3、在<head>头部添加<style>,在<style>中写样式

CSS 背景background的使用方法

4、第一个是background-color,

这个属性可以元素添加背景颜色,参数可以使用十六进制的#FF0000,

也可以用rgb(255,0,0),还可以用英文red

CSS 背景background的使用方法

CSS 背景background的使用方法

5、第二个background-image,

为背景添加背景图片

用法:background-image:url(图片地址),使用background-repeat:no-repeat属性去掉重复铺设

CSS 背景background的使用方法

CSS 背景background的使用方法

6、background-attachment:使用fixed参数使网页的背景图片固定,不会随着页面的滚动而变化位置

CSS 背景background的使用方法

7、background-position是设置背景图的位置,固定背景图的位置

CSS 背景background的使用方法

CSS 背景background的使用方法

© 2026 海能知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com