背景图

本文主要介绍了HTML和CSS中背景图的相关知识。阐述了背景图默认平铺、不占位置、显示范围由盒子大小决定等特点,还介绍了控制背景图平铺方式的background - repeat属性、设置背景图位置的background - position属性,以及控制背景图固定或滚动的background - attachment属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

背景图的特点:
1.背景图默认是平铺的
2.背景图不占位置
3.背景图的显示范围由盒子大小来决定的
盒子大小=背景图大小,将会看到一张完整的背景图
盒子大小>背景图大小,将会看到很多张背景图
想要看到一张背景图,需要background-repeat属性
background-repeat:no-repeat;
background-repeat:repeat;
background-repeat:repeat-x;
background-repeat:repeat-y;
盒子大小<背景图大小,将会看到一部分的背景图

背景图的位置:background-position属性(水平 垂直)
水平:
background-position:left;
background-position:right;
background-position:center;
垂直:
background-position:top;
background-position:bottom;
background-position:center;
简写:
background-position:center center;

		属性值用数字+单位(px或%)数字可以给负数
		background-position:0px-100px;盒子像素-图片像素
		background-position:0%-100%;(盒子一半-图片一半)/2

背景图固定/滚动:
background-attachment: scroll; 滚动
background-attachment: fixed; 固定
固定之后,是固定在浏览器窗口,所以在移动位置的时候,参照物就找浏览器窗口了,但可见范围还是盒子的范围

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值