首页 话题 小组 问答 好文 用户 我的社区 域名交易 唠叨

[分享]css3怎么设置背景

发布于 2024-11-11 15:35:10
0
23

使用CSS3来设置网页背景一般使用的是background属性。background属性有如下几个属性值:background-color、background-image、background-repeat、background-position、background-attachment。
background-color:该属性用于为元素设置背景颜色。
background-image:该属性用于为元素设置背景图片,常用于制作网站效果图、背景图等。
background-repeat:该属性用于定义是否重复背景图片。如果设置为no-repeat,则表示不重复;如果设置为repeat-x,则表示横向重复;如果设置为repeat-y,则表示纵向重复。
background-position:该属性用于定义背景图片的位置。可以使用“top left”、“top right”、“bottom left”、“bottom right”、“center center”等关键字,也可以使用百分比值或者像素值。
background-attachment:该属性用于定义背景图片的固定方式。如果设置为fixed,则表示背景图片会随着页面滚动而固定在元素的位置不动;如果设置为scroll,则表示背景图片会随着页面滚动而滚动。
下面是一个使用CSS3设置网页背景的例子:

p {
    background-color: #f5f5f5;
    background-image: url(bg.png);
    background-repeat: no-repeat;
    background-position: center center;
    background-attachment: fixed;
} 

这段代码表示为p标签设置了一个灰色背景颜色,并且添加了一张名为“bg.png”的背景图片,图片不重复,位于中间位置,固定不动。使用CSS3设置背景可以为网页增加很多美观和实用性,可以根据需要灵活处理。
评论
一个月内的热帖推荐
91云脑
Lv.1普通用户

62849

帖子

14

小组

291

积分

赞助商广告
站长交流