css 中的background-image、color、position、attachment、size、repeat

71 篇文章 0 订阅

# 再补充一个 background-size 

 例如:注意 background-size 设置的属性要和前边有一个 / 隔开,否则会语法报错

background: url(./assets/images/load.gif) no-repeat left center / contain;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
background-attachment属性指定背景图像是否固定或随着页面滚动而移动。它有以下几个值: 1. scroll(默认值):背景图像随着页面滚动而移动。 2. fixed:背景图像固定不动,不随着页面滚动而移动。 3. local:背景图像相对于元素内容固定,不随着页面滚动而移动。 以下是演示: ```html <!DOCTYPE html> <html> <head> <title>Background Attachment Demo</title> <style type="text/css"> body { height: 2000px; } .bg-scroll { background-image: url('https://picsum.photos/1200/800'); background-repeat: no-repeat; background-size: cover; background-position: center; background-attachment: scroll; } .bg-fixed { background-image: url('https://picsum.photos/1200/800'); background-repeat: no-repeat; background-size: cover; background-position: center; background-attachment: fixed; } .bg-local { background-image: url('https://picsum.photos/1200/800'); background-repeat: no-repeat; background-size: cover; background-position: center; background-attachment: local; height: 500px; overflow: scroll; } .content { padding: 50px; color: #fff; text-align: center; font-size: 2em; } </style> </head> <body> <div class="bg-scroll"> <div class="content"> Scroll Background </div> </div> <div class="bg-fixed"> <div class="content"> Fixed Background </div> </div> <div class="bg-local"> <div class="content"> Local Background </div> </div> </body> </html> ``` 以上代码将创建三个不同的元素,每个元素都有不同的background-attachment属性。第一个元素的背景图像随着页面滚动而移动,第二个元素的背景图像固定不动,第三个元素的背景图像相对于元素内容固定,只有元素内容区域内可以滚动。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值